Skip to content

Commit

Permalink
Merge pull request #49 from argetlam-coder/add-esp-idf-support
Browse files Browse the repository at this point in the history
Add support for the ESP-IDF framework
  • Loading branch information
DeimosHall authored Apr 29, 2024
2 parents cec1670 + ee1f8f9 commit 789de5e
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 9 deletions.
2 changes: 1 addition & 1 deletion API.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# CayenneLPP API Reference

The `CayenneLPP` class enables Arduino devices to encode data with the Cayenne Lower Power Protocol (LPP). [Read more about Cayenne LPP](https://mydevices.com/cayenne/docs/#lora-cayenne-low-power-payload)
The `CayenneLPP` class enables Arduino and ESP-IDF devices to encode data with the Cayenne Lower Power Protocol (LPP). [Read more about Cayenne LPP](https://mydevices.com/cayenne/docs/#lora-cayenne-low-power-payload)

### Class: `CayenneLPP`

Expand Down
18 changes: 18 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
cmake_minimum_required(VERSION 3.13)

if(ESP_PLATFORM)
# Build CayenneLPP as an ESP-IDF component
# required because ESP-IDF runs cmake in script mode
# and needs idf_component_register()
file(GLOB_RECURSE CAYENNELPP_ESP_SOURCES
"src/*.*"
)

idf_component_register(
SRCS ${CAYENNELPP_ESP_SOURCES}
INCLUDE_DIRS src
REQUIRES bblanchon__arduinojson
)

return()
endif()
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# CayenneLPP _by Electronic Cats_ - Library for Arduino
# CayenneLPP _by Electronic Cats_ - Library for Arduino and ESP-IDF

![LibraryBuild](https://github.com/ElectronicCats/CayenneLPP/workflows/LibraryBuild/badge.svg?branch=master)

This is an Arduino Library for Arduino Compatible with Cayenne Low Power Payload with Extended Data Types.
This is an Library for Arduino and ESP-IDF Compatible with Cayenne Low Power Payload with Extended Data Types.

CayenneLPP is a format designed by [myDevices](https://mydevices.com) to integrate LoRaWan nodes into their [IoT Platform](https://mydevices.com/capabilities). It is used to send sensor data in a packed way to [The Things Network platform](https://www.thethingsnetwork.org). You can read more on [myDevices CayenneLPP](https://docs.mydevices.com/docs/lorawan/cayenne-lpp)

Expand Down
13 changes: 13 additions & 0 deletions idf_component.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: "1.3.0"
description: "CayenneLPP library for Arduino and ESP-IDF. Compatible with Cayenne Low Power Payload."
tags: "communication, LoRa, LoRaWAN"
url: "https://github.com/ElectronicCats/CayenneLPP"
issues: https://github.com/ElectronicCats/CayenneLPP/issues
documentation: https://github.com/ElectronicCats/CayenneLPP/blob/master/API.md
repository: "https://github.com/ElectronicCats/CayenneLPP.git"
license: "MIT"
dependencies:
bblanchon/arduinojson:
version: "*"
maintainers:
"Electronic Cats <[email protected]>"
31 changes: 31 additions & 0 deletions library.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "CayenneLPP",
"version": "1.3.0",
"description": "CayenneLPP library for Arduino and ESP-IDF. Compatible with Cayenne Low Power Payload.",
"keywords": "communication, LoRa, LoRaWAN",
"homepage": "https://github.com/ElectronicCats/CayenneLPP",
"repository": {
"type": "git",
"url": "https://github.com/ElectronicCats/CayenneLPP.git"
},
"authors": {
"name": "Electronic Cats",
"email": "[email protected]",
"maintainer": true
},
"license": "MIT",
"frameworks":[
"arduino",
"espidf"
],
"platforms": "*",
"headers": "CayenneLPP.h",
"dependencies":
{
"bblanchon/ArduinoJson": "*"
},
"build":
{
"libLDFMode": "chain+"
}
}
16 changes: 13 additions & 3 deletions src/CayenneLPP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ uint32_t CayenneLPP::getValue32(uint8_t * buffer, uint8_t size) {

}

#ifdef ARDUINO
#if defined(ARDUINO) || defined(IDF_VER)
uint8_t CayenneLPP::decode(uint8_t *buffer, uint8_t len, JsonArray& root) {

uint8_t count = 0;
Expand Down Expand Up @@ -967,8 +967,12 @@ uint8_t CayenneLPP::decode(uint8_t *buffer, uint8_t len, JsonArray& root) {
JsonObject data = root.createNestedObject();
data["channel"] = channel;
data["type"] = type;
#ifdef ARDUINO
data["name"] = String(getTypeName(type));

#else
data["name"] = std::string(getTypeName(type));
#endif

// Parse types
if (false) {
}
Expand Down Expand Up @@ -1059,7 +1063,11 @@ uint8_t CayenneLPP::decodeTTN(uint8_t *buffer, uint8_t len, JsonObject& root) {
}

// Init object
#ifdef ARDUINO
String name = String(getTypeName(type)) + "_" + channel;
#else
std::string name = std::string(getTypeName(type)) + "_" + std::to_string(channel);
#endif

// Parse types
if (false) {
Expand Down Expand Up @@ -1126,7 +1134,9 @@ uint8_t CayenneLPP::decodeTTN(uint8_t *buffer, uint8_t len, JsonObject& root) {
return count;

}
#else
#endif
// Non Arduino frameworks
#ifndef ARDUINO
uint8_t CayenneLPP::decode(uint8_t *buffer, uint8_t len, std::map<uint8_t, CayenneLPPMessage> &messageMap) {

uint8_t count = 0;
Expand Down
16 changes: 13 additions & 3 deletions src/CayenneLPP.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@
#ifndef CAYENNE_LPP_H
#define CAYENNE_LPP_H

// Arduino framework
#ifdef ARDUINO
#include <Arduino.h>
#include <ArduinoJson.h>
#else
#endif
// ESP-IDF framework
#if !defined(ARDUINO) && defined(IDF_VER)
#include <ArduinoJson.h>
#endif
// Non Arduino frameworks
#ifndef ARDUINO
#include <cstdint>
#include <map>
#include "CayenneLPPMessage.h"
Expand Down Expand Up @@ -121,10 +128,13 @@ class CayenneLPP {

// Decoder methods
const char *getTypeName(uint8_t type);
#ifdef ARDUINO
// Arduino or ESP-IDF framework
#if defined(ARDUINO) || defined(IDF_VER)
uint8_t decode(uint8_t *buffer, uint8_t size, JsonArray &root);
uint8_t decodeTTN(uint8_t *buffer, uint8_t size, JsonObject &root);
#else
#endif
// Non Arduino frameworks
#ifndef ARDUINO
uint8_t decode(uint8_t *buffer, uint8_t size, std::map<uint8_t, CayenneLPPMessage> &messageMap);
#endif

Expand Down
5 changes: 5 additions & 0 deletions src/CayenneLPPPolyline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,12 @@ void CayenneLPPPolyline::pushFirst(double lat, double lon, uint8_t factor) {
}

void CayenneLPPPolyline::writeHeader(int32_t lat, int32_t lon, uint8_t factor) {
// ESP-IDF framework
#if !defined(ARDUINO) && defined(IDF_VER)
m_buffer.resize(std::max(static_cast<long unsigned int>(m_buffer.size()), 8UL));
#else
m_buffer.resize(std::max(m_buffer.size(), 8UL));
#endif
m_buffer[0] = m_buffer.size();
m_buffer[1] = factor;
m_buffer[2] = (lat >> 16); m_buffer[3] = (lat >> 8); m_buffer[4] = (lat);
Expand Down
4 changes: 4 additions & 0 deletions src/CayenneLPPPolyline.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@

#include <utility>
#include <vector>
// ESP-IDF framework
#if !defined(ARDUINO) && defined(IDF_VER)
#include <stdint.h>
#endif

struct DeltaCoord;

Expand Down

0 comments on commit 789de5e

Please sign in to comment.