mirror of
https://github.com/manuelbl/ttn-esp32.git
synced 2025-06-15 12:24:27 +02:00
Enhanced deep sleep example
This commit is contained in:
parent
31b00f05a8
commit
9fd24c65ec
@ -15,6 +15,8 @@
|
|||||||
#include "esp_sleep.h"
|
#include "esp_sleep.h"
|
||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "nvs_flash.h"
|
#include "nvs_flash.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "TheThingsNetwork.h"
|
#include "TheThingsNetwork.h"
|
||||||
|
|
||||||
@ -47,7 +49,9 @@ const char *appKey = "????????????????????????????????";
|
|||||||
static TheThingsNetwork ttn;
|
static TheThingsNetwork ttn;
|
||||||
|
|
||||||
const unsigned TX_INTERVAL = 60;
|
const unsigned TX_INTERVAL = 60;
|
||||||
static uint8_t msgData[] = "Hello, world";
|
|
||||||
|
// This counter value is retained (in RTC memory) during deep sleep
|
||||||
|
RTC_DATA_ATTR int counter_in_rtc_mem;
|
||||||
|
|
||||||
void messageReceived(const uint8_t *message, size_t length, ttn_port_t port)
|
void messageReceived(const uint8_t *message, size_t length, ttn_port_t port)
|
||||||
{
|
{
|
||||||
@ -111,7 +115,10 @@ extern "C" void app_main(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
printf("Sending message...\n");
|
printf("Sending message...\n");
|
||||||
TTNResponseCode res = ttn.transmitMessage(msgData, sizeof(msgData) - 1);
|
counter_in_rtc_mem++;
|
||||||
|
char message[20];
|
||||||
|
sprintf(message, "Hello %d", counter_in_rtc_mem);
|
||||||
|
TTNResponseCode res = ttn.transmitMessage((uint8_t *)message, strlen(message));
|
||||||
printf(res == kTTNSuccessfulTransmission ? "Message sent.\n" : "Transmission failed.\n");
|
printf(res == kTTNSuccessfulTransmission ? "Message sent.\n" : "Transmission failed.\n");
|
||||||
|
|
||||||
// Wait until TTN communication is idle and save state
|
// Wait until TTN communication is idle and save state
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
#include "nvs_flash.h"
|
#include "nvs_flash.h"
|
||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
#include "esp_sleep.h"
|
#include "esp_sleep.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "ttn.h"
|
#include "ttn.h"
|
||||||
|
|
||||||
@ -46,7 +48,9 @@ const char *appKey = "????????????????????????????????";
|
|||||||
#define TTN_PIN_DIO1 35
|
#define TTN_PIN_DIO1 35
|
||||||
|
|
||||||
#define TX_INTERVAL 60 // in sec
|
#define TX_INTERVAL 60 // in sec
|
||||||
static uint8_t msgData[] = "Hello, world";
|
|
||||||
|
// This counter value is retained (in RTC memory) during deep sleep
|
||||||
|
RTC_DATA_ATTR int counter_in_rtc_mem;
|
||||||
|
|
||||||
|
|
||||||
void messageReceived(const uint8_t* message, size_t length, ttn_port_t port)
|
void messageReceived(const uint8_t* message, size_t length, ttn_port_t port)
|
||||||
@ -113,7 +117,10 @@ void app_main(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
printf("Sending message...\n");
|
printf("Sending message...\n");
|
||||||
ttn_response_code_t res = ttn_transmit_message(msgData, sizeof(msgData) - 1, 1, false);
|
counter_in_rtc_mem++;
|
||||||
|
char message[20];
|
||||||
|
sprintf(message, "Hello %d", counter_in_rtc_mem);
|
||||||
|
ttn_response_code_t res = ttn_transmit_message((uint8_t *)message, strlen(message), 1, false);
|
||||||
printf(res == TTN_SUCCESSFUL_TRANSMISSION ? "Message sent.\n" : "Transmission failed.\n");
|
printf(res == TTN_SUCCESSFUL_TRANSMISSION ? "Message sent.\n" : "Transmission failed.\n");
|
||||||
|
|
||||||
// Wait until TTN communication is idle and save state
|
// Wait until TTN communication is idle and save state
|
||||||
|
@ -105,7 +105,7 @@ void app_main(void)
|
|||||||
// ttn_set_max_tx_pow(14);
|
// ttn_set_max_tx_pow(14);
|
||||||
|
|
||||||
printf("Joining...\n");
|
printf("Joining...\n");
|
||||||
if (ttn_join_provisioned())
|
if (ttn_join())
|
||||||
{
|
{
|
||||||
printf("Joined.\n");
|
printf("Joined.\n");
|
||||||
xTaskCreate(sendMessages, "send_messages", 1024 * 4, (void* )0, 3, NULL);
|
xTaskCreate(sendMessages, "send_messages", 1024 * 4, (void* )0, 3, NULL);
|
||||||
|
Loading…
Reference in New Issue
Block a user