sending temperature via LoRaWAN

This commit is contained in:
2023-01-21 19:02:29 +01:00
parent c6f5aa112f
commit afa5506506
2 changed files with 43 additions and 11 deletions

View File

@ -60,18 +60,19 @@ static void prepareTxFrame( uint8_t port )
DS18B20.begin();
uint8_t cnt = DS18B20.getDS18Count();
Serial.printf("cnt: %d\n\r", cnt);
uint8_t addr[8];
DS18B20.getAddress(addr, 0);
Serial.printf("%02x %02x %02x %02x %02x %02x %02x %02x\n\r", addr[0], addr[1], addr[2], addr[3], addr[4], addr[5], addr[6], addr[7]);
DS18B20.requestTemperatures(); // send the command to get temperatures
uint32_t tempC = DS18B20.getTemp(addr);
Serial.printf("tempC: %08x\n\r", tempC);
const uint8_t SLOT_WIDTH = 8 + 4; // 8 bytes address, 4 bytes value
appDataSize = cnt * SLOT_WIDTH;
uint8_t *buf = appData;
for (uint8_t i = 0; i < cnt; i++) {
uint8_t *addr = (buf + (i * SLOT_WIDTH));
uint32_t *value = (uint32_t*) (buf + (i * SLOT_WIDTH) + 8);
appDataSize = 4;
appData[0] = 0x01;
appData[1] = 0x02;
appData[2] = 0x03;
appData[3] = 0x04;
DS18B20.getAddress(addr, 0);
Serial.printf("%02x %02x %02x %02x %02x %02x %02x %02x\n\r", addr[0], addr[1], addr[2], addr[3], addr[4], addr[5], addr[6], addr[7]);
DS18B20.requestTemperatures(); // send the command to get temperatures
*value = DS18B20.getTemp(addr);
Serial.printf("tempC: %08x\n\r", *value);
}
}
RTC_DATA_ATTR bool firstrun = true;