labels
This commit is contained in:
@ -8,6 +8,7 @@
|
|||||||
#define LED_GREEN 4
|
#define LED_GREEN 4
|
||||||
#define LED_BLUE 45
|
#define LED_BLUE 45
|
||||||
|
|
||||||
|
#define SEND_PERIOD 15000 // ms
|
||||||
|
#define LABEL_LENGTH 5
|
||||||
|
|
||||||
#endif /* _DEFINES_H_ */
|
#endif /* _DEFINES_H_ */
|
@ -6,6 +6,9 @@
|
|||||||
#include <OneWire.h>
|
#include <OneWire.h>
|
||||||
#include <DallasTemperature.h>
|
#include <DallasTemperature.h>
|
||||||
|
|
||||||
|
#include "HT_SSD1306Wire.h"
|
||||||
|
extern SSD1306Wire display;
|
||||||
|
|
||||||
|
|
||||||
// from config.cpp
|
// from config.cpp
|
||||||
extern config_t myConfig;
|
extern config_t myConfig;
|
||||||
@ -15,7 +18,7 @@ extern config_t myConfig;
|
|||||||
uint16_t userChannelsMask[6]={ 0x00FF,0x0000,0x0000,0x0000,0x0000,0x0000 };
|
uint16_t userChannelsMask[6]={ 0x00FF,0x0000,0x0000,0x0000,0x0000,0x0000 };
|
||||||
|
|
||||||
/*LoraWan Class, Class A and Class C are supported*/
|
/*LoraWan Class, Class A and Class C are supported*/
|
||||||
DeviceClass_t loraWanClass = CLASS_A;
|
DeviceClass_t loraWanClass = CLASS_C;
|
||||||
|
|
||||||
/*the application data transmission duty cycle. value in [ms].*/
|
/*the application data transmission duty cycle. value in [ms].*/
|
||||||
uint32_t appTxDutyCycle = 15000;
|
uint32_t appTxDutyCycle = 15000;
|
||||||
@ -54,15 +57,42 @@ uint8_t confirmedNbTrials = 4;
|
|||||||
OneWire oneWire(ONE_WIRE);
|
OneWire oneWire(ONE_WIRE);
|
||||||
DallasTemperature DS18B20(&oneWire);
|
DallasTemperature DS18B20(&oneWire);
|
||||||
|
|
||||||
|
bool firstrun = true;
|
||||||
|
|
||||||
|
char *labels;
|
||||||
|
uint8_t cnt;
|
||||||
|
|
||||||
/* Prepares the payload of the frame */
|
/* Prepares the payload of the frame */
|
||||||
static void prepareTxFrame( uint8_t port )
|
static void prepareTxFrame( uint8_t port )
|
||||||
{
|
{
|
||||||
|
display.clear();
|
||||||
|
|
||||||
DS18B20.begin();
|
DS18B20.begin();
|
||||||
uint8_t cnt = DS18B20.getDS18Count();
|
cnt = DS18B20.getDS18Count();
|
||||||
Serial.printf("cnt: %d\n\r", cnt);
|
Serial.printf("cnt: %d\n\r", cnt);
|
||||||
const uint8_t SLOT_WIDTH = 8 + 4; // 8 bytes address, 4 bytes value
|
const uint8_t SLOT_WIDTH = 1 + 8 + 4; // 1 byte statue, 8 bytes address, 4 bytes value
|
||||||
appDataSize = cnt * SLOT_WIDTH;
|
// status: 00: regular sending
|
||||||
|
// 01: very first sending, please send label mapping
|
||||||
|
appDataSize = 1 + (cnt * SLOT_WIDTH);
|
||||||
uint8_t *buf = appData;
|
uint8_t *buf = appData;
|
||||||
|
char *tmpLabels;
|
||||||
|
if (firstrun) {
|
||||||
|
*buf = 0x01;
|
||||||
|
firstrun = false;
|
||||||
|
labels = (char*) malloc(cnt * (LABEL_LENGTH + 1));
|
||||||
|
memset(labels, 0, cnt * (LABEL_LENGTH + 1));
|
||||||
|
tmpLabels = labels;
|
||||||
|
for (uint8_t i = 0; i < cnt; i++) {
|
||||||
|
snprintf(tmpLabels, LABEL_LENGTH + 1, "Sens%d", i);
|
||||||
|
tmpLabels += (LABEL_LENGTH + 1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
*buf = 0x00;
|
||||||
|
}
|
||||||
|
|
||||||
|
buf++;
|
||||||
|
tmpLabels = labels;
|
||||||
|
uint8_t yline = 0;
|
||||||
for (uint8_t i = 0; i < cnt; i++) {
|
for (uint8_t i = 0; i < cnt; i++) {
|
||||||
uint8_t *addr = (buf + (i * SLOT_WIDTH));
|
uint8_t *addr = (buf + (i * SLOT_WIDTH));
|
||||||
uint32_t *value = (uint32_t*) (buf + (i * SLOT_WIDTH) + 8);
|
uint32_t *value = (uint32_t*) (buf + (i * SLOT_WIDTH) + 8);
|
||||||
@ -72,16 +102,29 @@ static void prepareTxFrame( uint8_t port )
|
|||||||
DS18B20.requestTemperatures(); // send the command to get temperatures
|
DS18B20.requestTemperatures(); // send the command to get temperatures
|
||||||
*value = DS18B20.getTemp(addr);
|
*value = DS18B20.getTemp(addr);
|
||||||
Serial.printf("tempC: %08x\n\r", *value);
|
Serial.printf("tempC: %08x\n\r", *value);
|
||||||
|
float tempC = ((float)*value) / 128;
|
||||||
|
char dispbuf[128];
|
||||||
|
sprintf(dispbuf, "%s: %.2f °C", tmpLabels, tempC);
|
||||||
|
tmpLabels += (LABEL_LENGTH + 1);
|
||||||
|
display.drawString(1, yline, dispbuf);
|
||||||
|
yline += 17;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
display.display();
|
||||||
}
|
}
|
||||||
|
|
||||||
void downLinkDataHandle(McpsIndication_t *mcpsIndication)
|
void downLinkDataHandle(McpsIndication_t *mcpsIndication)
|
||||||
{
|
{
|
||||||
Serial.printf("+REV DATA:%s,RXSIZE %d,PORT %d\r\n",mcpsIndication->RxSlot?"RXWIN2":"RXWIN1",mcpsIndication->BufferSize,mcpsIndication->Port);
|
Serial.printf("+REV DATA:%s,RXSIZE %d,PORT %d\r\n",mcpsIndication->RxSlot?"RXWIN2":"RXWIN1",mcpsIndication->BufferSize,mcpsIndication->Port);
|
||||||
Serial.print("+REV DATA:");
|
Serial.print("+REV DATA:");
|
||||||
for(uint8_t i=0;i<mcpsIndication->BufferSize;i++)
|
|
||||||
{
|
if (mcpsIndication->BufferSize != cnt * (LABEL_LENGTH + 1)) {
|
||||||
Serial.printf("%02X",mcpsIndication->Buffer[i]);
|
Serial.println("illegal number of octets in downlink message");
|
||||||
|
} else {
|
||||||
|
for(uint8_t i=0;i<mcpsIndication->BufferSize;i++) {
|
||||||
|
Serial.printf("%02X",mcpsIndication->Buffer[i]);
|
||||||
|
}
|
||||||
|
memcpy(labels, mcpsIndication->Buffer, mcpsIndication->BufferSize);
|
||||||
}
|
}
|
||||||
Serial.println();
|
Serial.println();
|
||||||
uint32_t color=mcpsIndication->Buffer[0]<<16|mcpsIndication->Buffer[1]<<8|mcpsIndication->Buffer[2];
|
uint32_t color=mcpsIndication->Buffer[0]<<16|mcpsIndication->Buffer[1]<<8|mcpsIndication->Buffer[2];
|
||||||
@ -90,62 +133,61 @@ void downLinkDataHandle(McpsIndication_t *mcpsIndication)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
RTC_DATA_ATTR bool firstrun = true;
|
|
||||||
|
|
||||||
|
|
||||||
void productionSetup() {
|
void productionSetup() {
|
||||||
Serial.println("Starting");
|
Serial.println("Starting");
|
||||||
Mcu.begin();
|
Mcu.begin();
|
||||||
|
|
||||||
|
digitalWrite(Vext,LOW);
|
||||||
|
display.init();
|
||||||
|
display.setFont(ArialMT_Plain_16);
|
||||||
|
display.clear();
|
||||||
|
display.display();
|
||||||
|
|
||||||
deviceState = DEVICE_STATE_INIT;
|
deviceState = DEVICE_STATE_INIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
void productionLoop()
|
void productionLoop()
|
||||||
{
|
{
|
||||||
|
static uint32_t goingToSleepTime = 0;
|
||||||
|
static uint8_t subStateSleep = 0;
|
||||||
|
static uint32_t myCycleTime = 0;
|
||||||
|
|
||||||
digitalWrite(LED_GREEN, HIGH);
|
digitalWrite(LED_GREEN, HIGH);
|
||||||
|
|
||||||
switch( deviceState )
|
if (deviceState != DEVICE_STATE_SLEEP) {
|
||||||
{
|
Serial.printf("State: %d\n\r", deviceState);
|
||||||
|
}
|
||||||
|
switch( deviceState ) {
|
||||||
case DEVICE_STATE_INIT:
|
case DEVICE_STATE_INIT:
|
||||||
digitalWrite(LED_GREEN, LOW);
|
digitalWrite(LED_GREEN, LOW);
|
||||||
{
|
|
||||||
LoRaWAN.generateDeveuiByChipID();
|
LoRaWAN.generateDeveuiByChipID();
|
||||||
LoRaWAN.init(loraWanClass,loraWanRegion);
|
LoRaWAN.init(loraWanClass,loraWanRegion);
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
case DEVICE_STATE_JOIN:
|
case DEVICE_STATE_JOIN:
|
||||||
{
|
|
||||||
Serial.println("Joining");
|
Serial.println("Joining");
|
||||||
LoRaWAN.join();
|
LoRaWAN.join();
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
case DEVICE_STATE_SEND:
|
case DEVICE_STATE_SEND:
|
||||||
digitalWrite(LED_BLUE, HIGH);
|
digitalWrite(LED_BLUE, HIGH);
|
||||||
{
|
|
||||||
Serial.println("sending");
|
Serial.println("sending");
|
||||||
prepareTxFrame( appPort );
|
prepareTxFrame( appPort );
|
||||||
LoRaWAN.send();
|
LoRaWAN.send();
|
||||||
deviceState = DEVICE_STATE_CYCLE;
|
deviceState = DEVICE_STATE_CYCLE;
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
case DEVICE_STATE_CYCLE:
|
case DEVICE_STATE_CYCLE:
|
||||||
digitalWrite(LED_BLUE, LOW);
|
digitalWrite(LED_BLUE, LOW);
|
||||||
{
|
|
||||||
// Schedule next packet transmission
|
// Schedule next packet transmission
|
||||||
txDutyCycleTime = appTxDutyCycle + randr( -APP_TX_DUTYCYCLE_RND, APP_TX_DUTYCYCLE_RND );
|
txDutyCycleTime = appTxDutyCycle + randr( -APP_TX_DUTYCYCLE_RND, APP_TX_DUTYCYCLE_RND );
|
||||||
LoRaWAN.cycle(txDutyCycleTime);
|
LoRaWAN.cycle(txDutyCycleTime);
|
||||||
deviceState = DEVICE_STATE_SLEEP;
|
deviceState = DEVICE_STATE_SLEEP;
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
case DEVICE_STATE_SLEEP:
|
case DEVICE_STATE_SLEEP:
|
||||||
{
|
|
||||||
LoRaWAN.sleep(loraWanClass);
|
LoRaWAN.sleep(loraWanClass);
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
{
|
|
||||||
deviceState = DEVICE_STATE_INIT;
|
deviceState = DEVICE_STATE_INIT;
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user