-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 27612b1
Showing
10 changed files
with
558 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2019 Germán Martín | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# CayenneLPP decoder | ||
|
||
## Introduction | ||
|
||
CayenneLPP is a format designed by [myDevices](https://mydevices.com/about/) to integrate LoRaWan nodes into their IoT platform [Cayenne](https://mydevices.com/cayenne/features/). 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 https://mydevices.com/cayenne/docs/lora/#lora-cayenne-low-power-payload | ||
|
||
Most of this library code is based on [Gizmocut's CayeneLPPDecoder](https://github.com/gizmocuz/CayenneLPP-Decoder). This is a generic C++ based decoder. My work here was to adapat his code to Arduino platform. | ||
|
||
## Description | ||
CayenneLPP format is a quite well optimized way to send sensor data over low bit rate connection, like LoRa. You may find, probably, a better way for your specific project but CayenneLPP is a standarized and proven format that packs data in a suffiient way. It implements basic sensor types specified by [OMA SpecWorks](https://www.omaspecworks.org), formerly IPSO Alliance. | ||
|
||
For instance, it can transmit GPS data in 11 bytes, or 8 port digital I/O in 4 bytes. | ||
|
||
In addition, it supports multichannel data. It means that you can use it on multisensor devices. | ||
|
||
This decoder converts a CayenneLPP formatted buffer into a JSON array. | ||
|
||
Basic code structure is like this: | ||
|
||
``` | ||
StaticJsonBuffer<512> jsonBuffer; // Create a Json buffer big enough. You can use https://arduinojson.org/v5/assistant/ to do a calculation | ||
JsonArray& root = jsonBuffer.createArray (); // Create an array to parse data to | ||
CayenneLPPDec::ParseLPP (buffer, len, root); // Convert the data | ||
``` | ||
|
||
## Examples | ||
|
||
Please check examples folder into repository source code. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#include <CayenneLPPDec.h> | ||
|
||
#include <CayenneLPP.h> | ||
#include "helperFunctions.h" | ||
|
||
void setup () { | ||
Serial.begin (115200); Serial.println (); Serial.println (); | ||
|
||
// First, we create a CayenneLPP buffer to hold test data to decode | ||
CayenneLPP lpp (51); | ||
|
||
lpp.reset (); | ||
|
||
// Fill CayenneLPP buffer with some data | ||
lpp.addTemperature (1,25.564); | ||
lpp.addUnixTime (2, millis()); | ||
lpp.addGPS (3, 4.34, 40.22, 755); | ||
|
||
uint8_t *buffer = lpp.getBuffer (); | ||
uint16_t len = lpp.getSize (); | ||
|
||
// Dump buffer content for debugging | ||
Serial.printf ("LPP Buffer: %s\n\n", printHexBuffer (buffer, len)); | ||
|
||
// Create a Json buffer big enough. You can use https://arduinojson.org/v5/assistant/ to do a calculation | ||
StaticJsonBuffer<512> jsonBuffer; | ||
|
||
// Create an array to parse data to | ||
JsonArray& root = jsonBuffer.createArray (); | ||
|
||
// Call parser | ||
CayenneLPPDec::ParseLPP (buffer, len, root); | ||
|
||
// Print JSON data to serial | ||
root.prettyPrintTo (Serial); | ||
|
||
} | ||
|
||
void loop () { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// | ||
// | ||
// | ||
|
||
#include "helperFunctions.h" | ||
|
||
#define MAX_STR_LEN 200 | ||
char *printHexBuffer (const uint8_t *buffer, uint16_t len) { | ||
static char tempStr[MAX_STR_LEN]; | ||
int charIndex = 0; | ||
|
||
memset (tempStr, 0, MAX_STR_LEN); | ||
|
||
for (int i = 0; i < len; i++) { | ||
if (i < MAX_STR_LEN-1) { | ||
charIndex += sprintf (tempStr + charIndex, "%02X ", buffer[i]); | ||
} | ||
} | ||
return tempStr; | ||
} | ||
|
||
void initWiFi () { | ||
//WiFi.persistent (false); | ||
WiFi.mode (WIFI_AP); | ||
WiFi.softAP ("ESPNOW", nullptr, 3); | ||
WiFi.softAPdisconnect (false); | ||
|
||
DEBUG_INFO ("AP MAC address of this device is %s", WiFi.softAPmacAddress ().c_str()); | ||
DEBUG_INFO ("STA MAC address of this device is %s", WiFi.macAddress ().c_str ()); | ||
|
||
} | ||
|
||
#define MACSTR "%02X:%02X:%02X:%02X:%02X:%02X" | ||
|
||
bool mac2str (const uint8_t *mac, const char *buffer) { | ||
if (mac && buffer) { | ||
sprintf (const_cast<char *>(buffer), MACSTR, MAC2STR (mac)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// helperFunctions.h | ||
|
||
#ifndef _HELPERFUNCTIONS_h | ||
#define _HELPERFUNCTIONS_h | ||
|
||
|
||
#if defined(ARDUINO) && ARDUINO >= 100 | ||
#include "arduino.h" | ||
#else | ||
#include "WProgram.h" | ||
#endif | ||
#if defined(ESP8266) | ||
#include <ESP8266WiFi.h> | ||
#elif defined(ESP32) | ||
#include <WiFi.h> | ||
#endif | ||
|
||
//#define DEBUG_ESP_PORT Serial | ||
|
||
#define NO_DEBUG 0 | ||
#define ERROR 1 | ||
#define WARN 2 | ||
#define INFO 3 | ||
#define VERBOSE 4 | ||
|
||
#define DEBUG_LINE_PREFIX() DEBUG_ESP_PORT.printf ("[%u] %u free (%s:%d) ",millis(),ESP.getFreeHeap(),__FUNCTION__,__LINE__); | ||
|
||
#ifdef DEBUG_ESP_PORT | ||
#define DEBUG_LEVEL VERBOSE | ||
|
||
#if DEBUG_LEVEL >= VERBOSE | ||
#define DEBUG_VERBOSE(...) DEBUG_ESP_PORT.print("V "); DEBUG_LINE_PREFIX(); DEBUG_ESP_PORT.printf( __VA_ARGS__ ); DEBUG_ESP_PORT.println() | ||
#else | ||
#define DEBUG_VERBOSE(...) | ||
#endif | ||
|
||
#if DEBUG_LEVEL >= INFO | ||
#define DEBUG_INFO(...) DEBUG_ESP_PORT.print("I "); DEBUG_LINE_PREFIX(); DEBUG_ESP_PORT.printf( __VA_ARGS__ ); DEBUG_ESP_PORT.println() | ||
#else | ||
#define DEBUG_INFO(...) | ||
#endif | ||
|
||
#if DEBUG_LEVEL >= WARN | ||
#define DEBUG_WARN(...) DEBUG_ESP_PORT.print("W "); DEBUG_LINE_PREFIX(); DEBUG_ESP_PORT.printf( __VA_ARGS__ ); DEBUG_ESP_PORT.println() | ||
#else | ||
#define DEBUG_WARN(...) | ||
#endif | ||
|
||
#if DEBUG_LEVEL >= ERROR | ||
#define DEBUG_ERROR(...) DEBUG_ESP_PORT.print("E "); DEBUG_LINE_PREFIX(); DEBUG_ESP_PORT.printf( __VA_ARGS__ ); DEBUG_ESP_PORT.println() | ||
#else | ||
#define DEBUG_ERROR(...) | ||
#endif | ||
#else | ||
#define DEBUG_VERBOSE(...) | ||
#define DEBUG_INFO(...) | ||
#define DEBUG_WARN(...) | ||
#define DEBUG_ERROR(...) | ||
#endif | ||
|
||
char* printHexBuffer (const uint8_t *buffer, uint16_t len); | ||
|
||
bool mac2str (const uint8_t *mac, const char *buffer); | ||
|
||
void initWiFi (); | ||
|
||
#endif | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
####################################### | ||
# Syntax Coloring Map For OneSheeld | ||
####################################### | ||
|
||
####################################### | ||
# Datatypes (KEYWORD1) | ||
####################################### | ||
|
||
####################################### | ||
# Methods and Functions (KEYWORD2) | ||
####################################### | ||
ParseLPP KEYWORD2 RESERVED_WORD | ||
####################################### | ||
# Strcutures and Classes (KEYWORD3) | ||
####################################### | ||
CayenneLPPDec KEYWORD3 RESERVED_WORD | ||
####################################### | ||
# Constants And Literals (KEYWORD2) | ||
####################################### | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"name": "CayenneLPPdec", | ||
"frameworks": "arduino", | ||
"version": "0.1.0", | ||
"keywords": "sensor, comm, communication, packing, lpp, cayenne, cayennelpp", | ||
"platforms": "*", | ||
"license": "MIT", | ||
"dependencies" : | ||
[{ | ||
"name": "ArduinoJSON", | ||
"authors": "Benoit Blanchon", | ||
"version": "^5.13.4" | ||
}, | ||
{ | ||
"name": "CayenneLPP", | ||
"authors": "Electronic Cats", | ||
"version": "^1.0.1" | ||
}] | ||
"description": "CayenneLPP data decoder", | ||
"url": "https://github.com/gmag11/CayenneLPPdec", | ||
"authors": | ||
[{ | ||
"name": "Germán Martín", | ||
"email": "gmag11@gmail.com" | ||
}, | ||
{ | ||
"name": "gizmocuz", | ||
"url": "https://github.com/gizmocuz" | ||
}] | ||
"repository": | ||
{ | ||
"type": "git", | ||
"url": "https://github.com/gmag11/CayenneLPPdec.git" | ||
}, | ||
"examples": "examples/*/*.ino" | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
name=CayenneLPPdec | ||
version=0.1.0 | ||
author=German Martin | ||
maintainer=gizmocuz,German Martin | ||
sentence=CayenneLPP data decoder | ||
paragraph=Library to decode CayenneLPP encoded data to a JSON array. It is useful when you want to use this format to communicate sensors with your own gateways without using TTN. | ||
category=Communication | ||
url=https://github.com/gmag11/CayenneLPPdec | ||
architectures=* |
Oops, something went wrong.