Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
gmag11 committed Feb 21, 2019
0 parents commit 27612b1
Show file tree
Hide file tree
Showing 10 changed files with 558 additions and 0 deletions.
21 changes: 21 additions & 0 deletions LICENSE
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.
28 changes: 28 additions & 0 deletions README.md
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.
41 changes: 41 additions & 0 deletions examples/CayenneLPPdec_test/CayenneLPPdec_test.ino
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 () {

}
39 changes: 39 additions & 0 deletions examples/CayenneLPPdec_test/helperFunctions.cpp
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));
}
}
68 changes: 68 additions & 0 deletions examples/CayenneLPPdec_test/helperFunctions.h
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

21 changes: 21 additions & 0 deletions keywords.txt
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)
#######################################


37 changes: 37 additions & 0 deletions library.json
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"
}

9 changes: 9 additions & 0 deletions library.properties
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=*
Loading

0 comments on commit 27612b1

Please sign in to comment.