Hi All,
I would like to use a Cubecell dev board to measure temperature using a DS18B20 and send it to TTN via LoRaWan alongside a current battery voltage reading before going into deep sleep for a period of time.
I thought a good starting point for me as a rookie would be to look at the LoRaWan sensor examples provided in Arduino IDE.
The problem is, I’m having difficulty understanding how to construct the payload. Does anybody know where I can find some documentation so that I can understand exactly what is going on in this code? Its not clear to me what a “puc” is.
* \brief Prepares the payload of the frame
*/
HDC1080 hdc1080;
static void prepareTxFrame( uint8_t port )
{
/*appData size is LORAWAN_APP_DATA_MAX_SIZE which is defined in "commissioning.h".
*appDataSize max value is LORAWAN_APP_DATA_MAX_SIZE.
*if enabled AT, don't modify LORAWAN_APP_DATA_MAX_SIZE, it may cause system hanging or failure.
*if disabled AT, LORAWAN_APP_DATA_MAX_SIZE can be modified, the max value is reference to lorawan region and SF.
*for example, if use REGION_CN470,
*the max value for different DR can be found in MaxPayloadOfDatarateCN470 refer to DataratesCN470 and BandwidthsCN470 in "RegionCN470.h".
*/
pinMode(Vext,OUTPUT);
digitalWrite(Vext,LOW);
hdc1080.begin(0x40);
float temperature = (float)(hdc1080.readTemperature());
float humidity = (float)(hdc1080.readHumidity());
hdc1080.end();
digitalWrite(Vext,HIGH);
uint16_t batteryVoltage = getBatteryVoltage();
unsigned char *puc;
puc = (unsigned char *)(&temperature);
appDataSize = 10;
appData[0] = puc[0];
appData[1] = puc[1];
appData[2] = puc[2];
appData[3] = puc[3];
puc = (unsigned char *)(&humidity);
appData[4] = puc[0];
appData[5] = puc[1];
appData[6] = puc[2];
appData[7] = puc[3];
appData[8] = (uint8_t)(batteryVoltage>>8);
appData[9] = (uint8_t)batteryVoltage;
}
Given that the DS18B20 is one of the most common sensors that noobs play with, would it be a good idea to provide a commented example for people like me to learn from?
Thanks,
Dan