|
EnigmaIOT
0.9.8
Secure sensor and gateway platform based on ESP8266 and ESP32
|
Go to the documentation of this file.
9 #if !defined ESP8266 && !defined ESP32
10 #error Node only supports ESP8266 or ESP32 platform
20 #include <CayenneLPP.h>
21 #include <ArduinoJson.h>
24 #include <ESP8266WiFi.h>
25 #include <ESP8266HTTPClient.h>
26 #include <ESP8266httpUpdate.h>
27 #include <ESPAsyncTCP.h>
35 #include <driver/adc.h>
38 #include <ArduinoJson.h>
39 #include <Curve25519.h>
40 #include <ESPAsyncWebServer.h>
41 #include <ESPAsyncWiFiManager.h>
42 #include <DNSServer.h>
45 #define SLEEPY 0 // Set it to 1 if your node should sleep after sending data
48 #define LED_BUILTIN 2 // ESP32 boards normally have a LED in GPIO3 or GPIO5
49 #endif // !LED_BUILTIN
52 #define USE_SERIAL // Don't forget to set DEBUG_LEVEL to NONE if serial is disabled
54 #define BLUE_LED LED_BUILTIN // You can set a different LED pin here. -1 means disabled
58 #define RESET_PIN 13 // You can set a different configuration reset pin here. Check for conflicts with used pins.
71 DEBUG_WARN (
"Connected");
76 DEBUG_WARN (
"Disconnected. Reason %d", reason);
93 DEBUG_INFO (
"Command processed");
95 DEBUG_WARN (
"Command error");
112 Serial.begin (921600);
117 if (FailSafe.isActive ()) {
134 DEBUG_WARN (
"Error reading config file");
135 if (FILESYSTEM.format ())
136 DEBUG_WARN (
"SPIFFS Formatted");
147 if (wifi_get_macaddr (STATION_IF, macAddress))
149 if ((esp_wifi_get_mac (WIFI_IF_STA, macAddress) == ESP_OK))
154 DEBUG_DBG (
"Node address set to %s",
mac2str (macAddress, macStr));
156 DEBUG_WARN (
"Node address error");
166 DEBUG_DBG (
"END setup");
172 if (FailSafe.isActive ()) {
177 #if SUPPORT_HA_DISCOVERY
179 #endif // SUPPORT_HA_DISCOVERY
virtual void loop()=0
This should be called periodically for module handling.
virtual void configManagerStart()=0
Called when wifi manager starts config portal.
virtual void configManagerExit(bool status)=0
Called when wifi manager exits config portal.
void connectEventHandler()
void enableClockSync(bool clockSync=true)
Controls clock synchronization function.
static const size_t ENIGMAIOT_ADDR_LEN
Address size. Mac address = 6 bytes.
nodeMessageType
Message code definition.
void setResetPin(int pin)
Sets a pin to be used to reset configuration it it is connected to ground during startup.
virtual void connectInform()
Used to notify controller that it is registered on EnigmaIOT network.
void setSleepTime(uint32_t sleepTime, bool forceSleepForever=false)
Allows to configure a new sleep time period from user code.
void handle()
This method should be called periodically for instance inside loop() function. It is used for interna...
void sendDataCallback(sendData_cb cb)
Register send data callback to run when module needs to send a message.
const time_t BOOT_FLAG_TIMEOUT
const int MAX_CONSECUTIVE_BOOT
virtual bool loadConfig()=0
Loads output module configuration.
EnigmaIOTjsonController * controller
EnigmaIOTNodeClass EnigmaIOTNode
void sleep()
Requests transition to sleep mode (low energy state)
void onWiFiManagerExit(onWiFiManagerExit_t handle)
Register callback to be called on wifi manager exit.
void onDisconnected(onDisconnected_t handler)
Defines a function callback that will be called everytime node is disconnected from gateway.
void disconnectEventHandler(nodeInvalidateReason_t reason)
bool sendData(const uint8_t *data, size_t len, dataMessageType_t dataMsgType, bool encrypt=true, nodePayloadEncoding_t payloadEncoding=CAYENNELPP)
Initiades data transmission distinguissing if it is payload or control data.
void onWiFiManagerStarted(simpleEventHandler_t handle)
Register callback to be called on wifi manager start.
virtual bool processRxCommand(const uint8_t *mac, const uint8_t *buffer, uint8_t length, nodeMessageType_t command, nodePayloadEncoding_t payloadEncoding)=0
Called to process a downlink command.
Library to build a node for EnigmaIoT system.
bool sendHADiscoveryMessage(const uint8_t *data, size_t len)
Builds, encrypts and sends a HomeAssistant discovery message.
void onConnected(onConnected_t handler)
Defines a function callback that will be called everytime node is registered on gateway.
virtual void setup(EnigmaIOTNodeClass *node, void *config=NULL)=0
Initialize data structures.
void begin(Comms_halClass *comm, uint8_t *gateway=NULL, uint8_t *networkKey=NULL, bool useCounter=true, bool sleepy=true)
Initalizes communication basic data and starts node registration.
const int FAILSAFE_RTC_ADDRESS
Espnow_halClass Espnow_hal
Singleton instance of ESP-NOW class.
void wifiManagerExit(boolean status)
char * mac2str(const uint8_t *mac, char *extBuffer)
Debug helper function that generates a string that represent a MAC address.
void processRxData(const uint8_t *mac, const uint8_t *buffer, uint8_t length, nodeMessageType_t command, nodePayloadEncoding_t payloadEncoding)
bool setNodeAddress(uint8_t address[ENIGMAIOT_ADDR_LEN])
Set node address to be used in EnigmaIOT communication.
nodeInvalidateReason_t
Key invalidation reason definition.
Prototype for JSON/MSGPACK based controller node.
void wifiManagerStarted()
ESP-NOW communication system abstraction layer. To be used on ESP8266 or ESP32 platforms.
bool sendUplinkData(const uint8_t *data, size_t len, nodePayloadEncoding_t payloadEncoding, dataMessageType_t dataMsgType)
void onDataRx(onNodeDataRx_t handler)
Defines a function callback that will be called on every downlink data message that is received from ...