node payload structure
parent
615f36405d
commit
7c67644ccb
|
@ -5,24 +5,29 @@
|
|||
void sendMessages(void* pvParameter)
|
||||
{
|
||||
while (1) {
|
||||
printf("Sending message...\n");
|
||||
dummyPayload();
|
||||
printf("Sending msg...\n");
|
||||
ssd1306_display_clear();
|
||||
const char *pcTask1 = "Sending message...\n";
|
||||
const char *pcTask1 = "Sending msg...\n";
|
||||
xTaskCreate(&task_ssd1306_display_text, "task_ssd1306_display_text", 4096, (void *) pcTask1, 5, NULL);
|
||||
TTNResponseCode res = ttn.transmitMessage(msgData, sizeof(msgData) - 1);
|
||||
TTNResponseCode res = ttn.transmitMessage((uint8_t*) &pDummyPayload, sizeof(pDummyPayload));
|
||||
|
||||
if(res == kTTNSuccessfulTransmission){
|
||||
printf("Message sent.\n");
|
||||
printf("msg sent.\n");
|
||||
ssd1306_display_clear();
|
||||
const char *pcTask1 = "Message sent.\n";
|
||||
const char *pcTask1 = "msg sent.\n";
|
||||
xTaskCreate(&task_ssd1306_display_text, "task_ssd1306_display_text", 4096, (void *) pcTask1, 5, NULL);
|
||||
}else{
|
||||
printf("Transmission failed.\n");
|
||||
printf("Transm failed.\n");
|
||||
ssd1306_display_clear();
|
||||
const char *pcTask1 = "Transmission failed.\n";
|
||||
const char *pcTask1 = "Transm failed.\n";
|
||||
xTaskCreate(&task_ssd1306_display_text, "task_ssd1306_display_text", 4096, (void *) pcTask1, 5, NULL);
|
||||
}
|
||||
|
||||
printf("sleeping...\n");
|
||||
ssd1306_display_clear();
|
||||
const char *pcTask2 = "sleeping...\n";
|
||||
xTaskCreate(&task_ssd1306_display_text, "task_ssd1306_display_text", 4096, (void *) pcTask2, 5, NULL);
|
||||
vTaskDelay(TX_INTERVAL * pdMS_TO_TICKS(1000));
|
||||
}
|
||||
}
|
||||
|
@ -35,6 +40,28 @@ void messageReceived(const uint8_t* message, size_t length, ttn_port_t port)
|
|||
printf("\n");
|
||||
}
|
||||
|
||||
void dummyPayload(){
|
||||
|
||||
uint16_t u16Temperature = (uint16_t) esp_random();
|
||||
uint16_t u16Pressure = (uint16_t) esp_random();
|
||||
uint16_t u16Windspeed = (uint16_t) esp_random();
|
||||
uint16_t u16Winddirection = (uint16_t) esp_random();
|
||||
|
||||
if((esp_random()%2) == 0){
|
||||
pDummyPayload.auxState = AUX_STATE_DOOR_CLOSED;
|
||||
}else{
|
||||
pDummyPayload.auxState = AUX_STATE_DOOR_OPEN;
|
||||
}
|
||||
|
||||
memcpy(pDummyPayload.degreesC, &u16Temperature, 2);
|
||||
memcpy(pDummyPayload.pressure, &u16Pressure, 2);
|
||||
memcpy(pDummyPayload.windspeed, &u16Windspeed, 2);
|
||||
memcpy(pDummyPayload.winddirection, &u16Winddirection, 2);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
extern "C" void app_main(void)
|
||||
{
|
||||
esp_err_t err;
|
||||
|
@ -66,6 +93,7 @@ extern "C" void app_main(void)
|
|||
// Register callback for received messages
|
||||
ttn.onMessage(messageReceived);
|
||||
|
||||
printf("random: %li\n", esp_random());
|
||||
|
||||
i2c_master_init();
|
||||
ssd1306_init();
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
#include "driver/gpio.h"
|
||||
#include "nvs_flash.h"
|
||||
#include "driver/i2c.h"
|
||||
#include "esp_random.h"
|
||||
#include <cstring>
|
||||
|
||||
#include "TheThingsNetwork.h"
|
||||
|
||||
|
@ -27,7 +29,23 @@
|
|||
static TheThingsNetwork ttn;
|
||||
|
||||
const unsigned TX_INTERVAL = 60*15;
|
||||
static uint8_t msgData[] = "BBBBBBBB"; //8x 0x
|
||||
//static uint8_t msgData[] = "BBBBBBBB"; //8x 0x
|
||||
|
||||
#define AUX_STATE_DOOR_OPEN 0x1
|
||||
#define AUX_STATE_DOOR_CLOSED 0x2
|
||||
|
||||
struct payload {
|
||||
uint8_t degreesC[2];
|
||||
uint8_t pressure[2];
|
||||
uint8_t windspeed[2];
|
||||
uint8_t winddirection[2];
|
||||
uint8_t auxState;
|
||||
};
|
||||
|
||||
|
||||
static struct payload pDummyPayload;
|
||||
|
||||
|
||||
void dummyPayload(void);
|
||||
|
||||
#endif /* MAIN_H */
|
Loading…
Reference in New Issue