-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
249 additions
and
315 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,44 @@ | ||
#define USE_ESP_IDF_LOG | ||
|
||
#include <Arduino.h> | ||
#include <SailtrackModule.h> | ||
|
||
SailtrackModule stm; | ||
// -------------------------- Configuration -------------------------- // | ||
|
||
#define MQTT_PUBLISH_FREQ_HZ 1 | ||
|
||
#define LOOP_TASK_DELAY_MS 1000 / MQTT_PUBLISH_FREQ_HZ | ||
|
||
static const char * LOG_TAG = "SAILTRACK_COUNTER"; | ||
// ------------------------------------------------------------------- // | ||
|
||
class TestCallbacks: public SailtrackModuleCallbacks { | ||
void onDeepSleepEnter() {} | ||
void onWifiConnectionBegin() {} | ||
void onWifiConnectionResult(wl_status_t status) {} | ||
void onWifiDisconnected() {} | ||
void onMqttConnectionBegin() {} | ||
void onMqttConnectionResult(bool connected) {} | ||
void onMqttDisconnected() {} | ||
SailtrackModule stm; | ||
|
||
class ModuleCallbacks: public SailtrackModuleCallbacks { | ||
void onLogMessage() { | ||
log_i("Extra log entry"); | ||
log_printf("\n"); | ||
} | ||
|
||
DynamicJsonDocument * getStatus() { return NULL; } | ||
void onStatusMessage(JsonObject status) { | ||
status["extra"] = "extraStatus"; | ||
} | ||
|
||
void onMqttMessage(const char * topic, const char * message) { | ||
ESP_LOGI(LOG_TAG, "New message! Topic: %s, Message: %s", topic, message); | ||
void onMqttMessage(const char * topic, JsonObjectConst payload) { | ||
char message[STM_MQTT_DATA_BUFFER_SIZE]; | ||
serializeJson(payload, message); | ||
log_i("New message! Topic: %s, Message: %s", topic, message); | ||
} | ||
}; | ||
|
||
int counter = 0; | ||
|
||
void setup() { | ||
stm.begin("counter", IPAddress(192, 168, 42, 100), new TestCallbacks()); | ||
stm.begin("counter", IPAddress(192, 168, 42, 100), new ModuleCallbacks()); | ||
stm.subscribe("sensor/counter0"); | ||
esp_log_level_set(LOG_TAG, ESP_LOG_INFO); | ||
} | ||
|
||
void loop() { | ||
DynamicJsonDocument data(100); | ||
data["count"] = counter++; | ||
stm.publish("sensor/counter0", &data); | ||
delay(1000); | ||
TickType_t lastWakeTime = xTaskGetTickCount(); | ||
StaticJsonDocument<STM_JSON_DOCUMENT_SMALL_SIZE> doc; | ||
doc["count"] = counter++; | ||
stm.publish("sensor/counter0", doc.as<JsonObjectConst>()); | ||
vTaskDelayUntil(&lastWakeTime, pdMS_TO_TICKS(LOOP_TASK_DELAY_MS)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#ifndef SAILTRACK_MODULE_CONFIG_H | ||
#define SAILTRACK_MODULE_CONFIG_H | ||
|
||
// ----------------------- Module Configuration ----------------------- // | ||
|
||
#define STM_MODULE_NAME_MAX_LENGTH 16 | ||
|
||
// ------------------- JSON Documents Configuration ------------------- // | ||
|
||
#define STM_JSON_DOCUMENT_BIG_SIZE 1024 | ||
#define STM_JSON_DOCUMENT_MEDIUM_SIZE 512 | ||
#define STM_JSON_DOCUMENT_SMALL_SIZE 256 | ||
|
||
// ------------------ Notification LED Configuration ------------------ // | ||
|
||
#ifndef STM_NOTIFICATION_LED_PIN | ||
#ifdef LED_BUILTIN | ||
#define STM_NOTIFICATION_LED_PIN LED_BUILTIN | ||
#else | ||
#ifdef BUILTIN_LED | ||
#define STM_NOTIFICATION_LED_PIN BUILTIN_LED | ||
#endif | ||
#endif | ||
#endif | ||
#ifndef STM_NOTIFICATION_LED_ON_STATE | ||
#define STM_NOTIFICATION_LED_ON_STATE HIGH | ||
#endif | ||
|
||
// ----------------------- Tasks Configuration ----------------------- // | ||
|
||
#define STM_TASK_HIGH_PRIORITY 3 | ||
#define STM_TASK_MEDIUM_PRIORITY 2 | ||
#define STM_TASK_LOW_PRIORITY 1 | ||
|
||
#define STM_TASK_BIG_STACK_SIZE 8192 | ||
#define STM_TASK_MEDIUM_STACK_SIZE 4096 | ||
#define STM_TASK_SMALL_STACK_SIZE 2048 | ||
|
||
// ------------------- Library Tasks Configuration ------------------- // | ||
|
||
#define STM_STATUS_PUBLISH_FREQ_HZ 0.1 | ||
#define STM_LOG_PRINT_FREQ_HZ 0.1 | ||
#define STM_OTA_HANDLE_FREQ_HZ 1 | ||
|
||
#define STM_STATUS_TASK_DELAY_MS 1000 / STM_STATUS_PUBLISH_FREQ_HZ | ||
#define STM_LOG_TASK_DELAY_MS 1000 / STM_LOG_PRINT_FREQ_HZ | ||
#define STM_OTA_TASK_DELAY_MS 1000 / STM_OTA_HANDLE_FREQ_HZ | ||
|
||
// ------------------------ WiFi Configuration ------------------------ // | ||
|
||
#ifndef STM_WIFI_SSID | ||
#define STM_WIFI_SSID "SailTrack-Net" | ||
#endif | ||
#ifndef STM_WIFI_PASSWORD | ||
#define STM_WIFI_PASSWORD "sailtracknet" | ||
#endif | ||
#ifndef STM_WIFI_GATEWAY_ADDR | ||
#define STM_WIFI_GATEWAY_ADDR "192.168.42.1" | ||
#endif | ||
#ifndef STM_WIFI_SUBNET | ||
#define STM_WIFI_SUBNET "255.255.255.0" | ||
#endif | ||
|
||
#define STM_WIFI_CONNECTION_TIMEOUT_MS 10 * 1e3 | ||
#define STM_WIFI_SLEEP_DURATION_US 60 * 1e6 | ||
|
||
// ------------------------ MQTT Configuration ------------------------ // | ||
|
||
#ifndef STM_MQTT_HOST_ADDR | ||
#define STM_MQTT_HOST_ADDR STM_WIFI_GATEWAY_ADDR | ||
#endif | ||
#ifndef STM_MQTT_PORT | ||
#define STM_MQTT_PORT MQTT_TCP_DEFAULT_PORT | ||
#endif | ||
#ifndef STM_MQTT_USERNAME | ||
#define STM_MQTT_USERNAME "mosquitto" | ||
#endif | ||
#ifndef STM_MQTT_PASSWORD | ||
#define STM_MQTT_PASSWORD "dietpi" | ||
#endif | ||
#define STM_MQTT_DATA_BUFFER_SIZE 1024 | ||
#define STM_MQTT_TOPIC_BUFFER_SIZE 32 | ||
|
||
#define STM_MQTT_CONNECTION_TIMEOUT_MS STM_WIFI_CONNECTION_TIMEOUT_MS | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.