cayenne format update

This commit is contained in:
Klaus K Wilting 2018-07-21 13:36:49 +02:00
parent 742050f01b
commit d38151a9e3
6 changed files with 23 additions and 45 deletions

View File

@ -16,8 +16,8 @@
;env_default = heltec ;env_default = heltec
;env_default = ttgov1 ;env_default = ttgov1
;env_default = ttgov2 ;env_default = ttgov2
env_default = ttgov21 ;env_default = ttgov21
;env_default = ttgobeam env_default = ttgobeam
;env_default = lopy ;env_default = lopy
;env_default = lopy4 ;env_default = lopy4
;env_default = fipy ;env_default = fipy

View File

@ -10,11 +10,11 @@ gpsStatus_t gps_status;
// read GPS data and cast to global struct // read GPS data and cast to global struct
void gps_read() { void gps_read() {
gps_status.latitude = (uint32_t)(gps.location.lat() * 1e6); gps_status.latitude = (int32_t)(gps.location.lat() * 1e6);
gps_status.longitude = (uint32_t)(gps.location.lng() * 1e6); gps_status.longitude = (int32_t)(gps.location.lng() * 1e6);
gps_status.satellites = (uint8_t)gps.satellites.value(); gps_status.satellites = (uint8_t)gps.satellites.value();
gps_status.hdop = (uint16_t)gps.hdop.value(); gps_status.hdop = (uint16_t)gps.hdop.value();
gps_status.altitude = (uint16_t)gps.altitude.meters(); gps_status.altitude = (int16_t)gps.altitude.meters();
} }
// GPS serial feed FreeRTos Task // GPS serial feed FreeRTos Task

View File

@ -36,7 +36,7 @@
#define WIFI_CHANNEL_SWITCH_INTERVAL 50 // [seconds/100] -> 0,5 sec. #define WIFI_CHANNEL_SWITCH_INTERVAL 50 // [seconds/100] -> 0,5 sec.
// LoRa payload default parameters // LoRa payload default parameters
#define PAYLOAD_ENCODER 2 // select payload encoder: 1=Plain, 2=Packed, 3=CayenneLPP #define PAYLOAD_ENCODER 1 // select payload encoder: 1=Plain, 2=Packed, 3=CayenneLPP
#define SEND_SECS 120 // payload send cycle [seconds/2] -> 240 sec. #define SEND_SECS 120 // payload send cycle [seconds/2] -> 240 sec.
#define MEM_LOW 2048 // [Bytes] low memory threshold triggering a send cycle #define MEM_LOW 2048 // [Bytes] low memory threshold triggering a send cycle
#define RETRANSMIT_RCMD 5 // [seconds] wait time before retransmitting rcommand results #define RETRANSMIT_RCMD 5 // [seconds] wait time before retransmitting rcommand results
@ -50,6 +50,7 @@
#define STATUSPORT 2 // Port on which device sends remote command results #define STATUSPORT 2 // Port on which device sends remote command results
#define CONFIGPORT 3 // Port on which device sends gps query results #define CONFIGPORT 3 // Port on which device sends gps query results
#define GPSPORT 4 // Port on which device sends gps query results #define GPSPORT 4 // Port on which device sends gps query results
#define CAYENNEPORT 1 // Port used for Cayenne encoding
// Default RGB LED luminosity (in %) // Default RGB LED luminosity (in %)
#define RGBLUMINOSITY 30 // 30% #define RGBLUMINOSITY 30 // 30%

View File

@ -2,10 +2,6 @@
#include "globals.h" #include "globals.h"
#include "payload.h" #include "payload.h"
/* ---------------- plain format without special encoding ---------- */
#if PAYLOAD_ENCODER == 1
PayloadConvert::PayloadConvert(uint8_t size) { PayloadConvert::PayloadConvert(uint8_t size) {
buffer = (uint8_t *)malloc(size); buffer = (uint8_t *)malloc(size);
cursor = 0; cursor = 0;
@ -19,6 +15,10 @@ uint8_t PayloadConvert::getSize(void) { return cursor; }
uint8_t *PayloadConvert::getBuffer(void) { return buffer; } uint8_t *PayloadConvert::getBuffer(void) { return buffer; }
/* ---------------- plain format without special encoding ---------- */
#if PAYLOAD_ENCODER == 1
void PayloadConvert::addCount(uint16_t value1, uint16_t value2) { void PayloadConvert::addCount(uint16_t value1, uint16_t value2) {
buffer[cursor++] = value1 >> 8; buffer[cursor++] = value1 >> 8;
buffer[cursor++] = value1; buffer[cursor++] = value1;
@ -82,24 +82,12 @@ void PayloadConvert::addStatus(uint16_t voltage, uint64_t uptime, float cputemp)
buffer[cursor++] = (uint32_t)cputemp; buffer[cursor++] = (uint32_t)cputemp;
} }
#elif PAYLOAD_ENCODER == 2
/* ---------------- packed format with LoRa serialization Encoder ---------- */ /* ---------------- packed format with LoRa serialization Encoder ---------- */
// derived from // derived from
// https://github.com/thesolarnomad/lora-serialization/blob/master/src/LoraEncoder.cpp // https://github.com/thesolarnomad/lora-serialization/blob/master/src/LoraEncoder.cpp
PayloadConvert::PayloadConvert(uint8_t size) { #elif PAYLOAD_ENCODER == 2
buffer = (uint8_t *)malloc(size);
cursor = 0;
}
PayloadConvert::~PayloadConvert(void) { free(buffer); }
void PayloadConvert::reset(void) { cursor = 0; }
uint8_t PayloadConvert::getSize(void) { return cursor; }
uint8_t *PayloadConvert::getBuffer(void) { return buffer; }
void PayloadConvert::addCount(uint16_t value1, uint16_t value2) { void PayloadConvert::addCount(uint16_t value1, uint16_t value2) {
writeUint16(value1); writeUint16(value1);
@ -189,22 +177,10 @@ void PayloadConvert::writeBitmap(bool a, bool b, bool c, bool d, bool e, bool f,
writeUint8(bitmap); writeUint8(bitmap);
} }
#elif PAYLOAD_ENCODER == 3
/* ---------------- Cayenne LPP format ---------- */ /* ---------------- Cayenne LPP format ---------- */
//http://community.mydevices.com/t/cayenne-lpp-2-0/7510
PayloadConvert::PayloadConvert(uint8_t size) { #elif PAYLOAD_ENCODER == 3
buffer = (uint8_t *)malloc(size);
cursor = 0;
}
PayloadConvert::~PayloadConvert(void) { free(buffer); }
void PayloadConvert::reset(void) { cursor = 0; }
uint8_t PayloadConvert::getSize(void) { return cursor; }
uint8_t *PayloadConvert::getBuffer(void) { return buffer; }
void PayloadConvert::addCount(uint16_t value1, uint16_t value2) { void PayloadConvert::addCount(uint16_t value1, uint16_t value2) {
buffer[cursor++] = LPP_COUNT_WIFI_CHANNEL; buffer[cursor++] = LPP_COUNT_WIFI_CHANNEL;
@ -221,7 +197,7 @@ void PayloadConvert::addCount(uint16_t value1, uint16_t value2) {
void PayloadConvert::addGPS(gpsStatus_t value) { void PayloadConvert::addGPS(gpsStatus_t value) {
int32_t lat = value.latitude / 100; int32_t lat = value.latitude / 100;
int32_t lon = value.longitude / 100; int32_t lon = value.longitude / 100;
int32_t alt = value.altitude; int32_t alt = value.altitude * 100;
buffer[cursor++] = LPP_GPS_CHANNEL; buffer[cursor++] = LPP_GPS_CHANNEL;
buffer[cursor++] = LPP_GPS; buffer[cursor++] = LPP_GPS;
buffer[cursor++] = lat >> 16; buffer[cursor++] = lat >> 16;
@ -242,15 +218,16 @@ void PayloadConvert::addConfig(configData_t value) {
buffer[cursor++] = value.adrmode; buffer[cursor++] = value.adrmode;
} }
void PayloadConvert::addStatus(uint16_t voltage, uint64_t uptime, float cputemp) { void PayloadConvert::addStatus(uint16_t voltage, uint64_t uptime, float celsius) {
int16_t val = celsius * 10;
buffer[cursor++] = LPP_BATT_CHANNEL; buffer[cursor++] = LPP_BATT_CHANNEL;
buffer[cursor++] = LPP_ANALOG_INPUT; buffer[cursor++] = LPP_ANALOG_INPUT;
buffer[cursor++] = voltage >> 8; buffer[cursor++] = voltage >> 8;
buffer[cursor++] = voltage; buffer[cursor++] = voltage;
buffer[cursor++] = LPP_TEMP_CHANNEL; buffer[cursor++] = LPP_TEMP_CHANNEL;
buffer[cursor++] = LPP_TEMPERATURE; buffer[cursor++] = LPP_TEMPERATURE;
buffer[cursor++] = (uint16_t)cputemp >> 8; buffer[cursor++] = (uint16_t)val >> 8;
buffer[cursor++] = (uint16_t)cputemp; buffer[cursor++] = (uint16_t)val;
} }
#else #else

View File

@ -1,8 +1,6 @@
#ifndef _PAYLOAD_H_ #ifndef _PAYLOAD_H_
#define _PAYLOAD_H_ #define _PAYLOAD_H_
#include <Arduino.h>
// MyDevices CayenneLPP channels // MyDevices CayenneLPP channels
#define LPP_GPS_CHANNEL 20 #define LPP_GPS_CHANNEL 20
#define LPP_COUNT_WIFI_CHANNEL 21 #define LPP_COUNT_WIFI_CHANNEL 21
@ -10,6 +8,7 @@
#define LPP_BATT_CHANNEL 23 #define LPP_BATT_CHANNEL 23
#define LPP_ADR_CHANNEL 25 #define LPP_ADR_CHANNEL 25
#define LPP_TEMP_CHANNEL 26 #define LPP_TEMP_CHANNEL 26
// MyDevices CayenneLPP types // MyDevices CayenneLPP types
#define LPP_GPS 136 // 3 byte lon/lat 0.0001 °, 3 bytes alt 0.01m #define LPP_GPS 136 // 3 byte lon/lat 0.0001 °, 3 bytes alt 0.01m
#define LPP_TEMPERATURE 103 // 2 bytes, 0.1°C signed #define LPP_TEMPERATURE 103 // 2 bytes, 0.1°C signed

View File

@ -9,9 +9,10 @@ void senddata(uint8_t port) {
ESP_LOGI(TAG, "LoRa busy, data not sent"); ESP_LOGI(TAG, "LoRa busy, data not sent");
sprintf(display_line7, "LORA BUSY"); sprintf(display_line7, "LORA BUSY");
} else { } else {
// send payload via LoRa LMIC_setTxData2(PAYLOAD_ENCODER == 3 ? CAYENNEPORT : port,
LMIC_setTxData2(port, payload.getBuffer(), payload.getSize(), payload.getBuffer(), payload.getSize(),
(cfg.countermode & 0x02)); (cfg.countermode & 0x02));
ESP_LOGI(TAG, "%d bytes queued to send on LoRa", payload.getSize()); ESP_LOGI(TAG, "%d bytes queued to send on LoRa", payload.getSize());
sprintf(display_line7, "PACKET QUEUED"); sprintf(display_line7, "PACKET QUEUED");
} }