Cayenne Low Power Payload

Dependents:   LORAWAN-TTN-CAYENNE-LM35 ER4Lora gps_accelerometer sgam_mdw_test ... more

Committer:
eptak
Date:
Fri Dec 02 17:11:01 2016 +0000
Revision:
3:a65959c9e3b9
Parent:
2:ac824f095591
Child:
4:8d32c35e74ad
Completed example

Who changed what in which revision?

UserRevisionLine numberNew contents of line
eptak 2:ac824f095591 1 # Cayenne Low Power Payload
eptak 2:ac824f095591 2 Payload builder library
eptak 2:ac824f095591 3
eptak 2:ac824f095591 4
eptak 2:ac824f095591 5 # Example use
eptak 2:ac824f095591 6 ```
eptak 2:ac824f095591 7 #include 'CayenneLPP.h';
eptak 2:ac824f095591 8
eptak 2:ac824f095591 9 #define MAX_SIZE 200; // depends on spreading factor and frequency used
eptak 2:ac824f095591 10
eptak 2:ac824f095591 11 CayenneLPP Payload(MAX_SIZE);
eptak 2:ac824f095591 12
eptak 3:a65959c9e3b9 13 float celsius = -4.1;
eptak 2:ac824f095591 14 float accel[] = {1.234, -1.234, 0};
eptak 2:ac824f095591 15 float rh = 30;
eptak 3:a65959c9e3b9 16 float hpa = 1014.1;
eptak 3:a65959c9e3b9 17
eptak 3:a65959c9e3b9 18 int size = 0;
eptak 2:ac824f095591 19
eptak 2:ac824f095591 20 Payload.reset();
eptak 3:a65959c9e3b9 21 size = Payload.addTemperature(0, celsius);
eptak 3:a65959c9e3b9 22
eptak 3:a65959c9e3b9 23 if (size == 0) {
eptak 3:a65959c9e3b9 24 // not enough byte left to add the data
eptak 3:a65959c9e3b9 25 }
eptak 3:a65959c9e3b9 26
eptak 3:a65959c9e3b9 27 else {
eptak 3:a65959c9e3b9 28 // add function returned current payload size
eptak 3:a65959c9e3b9 29 }
eptak 3:a65959c9e3b9 30
eptak 3:a65959c9e3b9 31
eptak 2:ac824f095591 32 Payload.addAccelerometer(1, accel[0], accel[1], accel[2]);
eptak 2:ac824f095591 33 Payload.addRelativeHumidity(3, rh);
eptak 3:a65959c9e3b9 34 Payload.addBarometricPressure(4, hpa);
eptak 2:ac824f095591 35
eptak 3:a65959c9e3b9 36 // Call LoRaWAN library to send the frame
eptak 2:ac824f095591 37 LORA_SEND(Payload.getBuffer(), Payload.getSize());
eptak 2:ac824f095591 38 ```