|
EnigmaIOT
0.9.8
Secure sensor and gateway platform based on ESP8266 and ESP32
|
Go to the documentation of this file.
13 #if !defined ESP8266 && !defined ESP32
14 #error Node only supports ESP8266 or ESP32 platform
22 #include <DallasTemperature.h>
26 #include <CayenneLPP.h>
27 #include <ArduinoJson.h>
30 #include <ESP8266WiFi.h>
31 #include <ESP8266HTTPClient.h>
32 #include <ESP8266httpUpdate.h>
33 #include <ESPAsyncTCP.h>
39 #include <driver/adc.h>
42 #include <ArduinoJson.h>
43 #include <Curve25519.h>
44 #include <ESPAsyncWebServer.h>
45 #include <ESPAsyncWiFiManager.h>
46 #include <DNSServer.h>
49 #define SLEEPY 1 // Set it to 1 if your node should sleep after sending data
52 #define LED_BUILTIN 2 // ESP32 boards normally have a LED in GPIO3 or GPIO5
53 #endif // !LED_BUILTIN
56 #define USE_SERIAL // Don't forget to set DEBUG_LEVEL to NONE if serial is disabled
58 #define BLUE_LED LED_BUILTIN // You can set a different LED pin here. -1 means disabled
62 #define RESET_PIN 13 // You can set a different configuration reset pin here. Check for conflicts with used pins.
75 DEBUG_WARN (
"Connected");
80 DEBUG_WARN (
"Disconnected. Reason %d", reason);
97 DEBUG_INFO (
"Command processed");
99 DEBUG_WARN (
"Command error");
116 Serial.begin (921600);
122 if (FailSafe.isActive ()) {
141 DEBUG_WARN (
"Error reading config file");
142 if (FILESYSTEM.format ())
143 DEBUG_WARN (
"Filesystem Formatted");
154 if (wifi_get_macaddr (STATION_IF, macAddress))
156 if ((esp_wifi_get_mac (WIFI_IF_STA, macAddress) == ESP_OK))
160 DEBUG_DBG (
"Node address set to %s",
mac2str (macAddress));
162 DEBUG_WARN (
"Node address error");
172 DEBUG_DBG (
"END setup");
178 if (FailSafe.isActive ()) {
183 #if SUPPORT_HA_DISCOVERY
185 #endif // SUPPORT_HA_DISCOVERY
189 FailSafe.resetFlag ();
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 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 processRxData(const uint8_t *mac, const uint8_t *buffer, uint8_t length, nodeMessageType_t command, nodePayloadEncoding_t payloadEncoding)
void setResetPin(int pin)
Sets a pin to be used to reset configuration it it is connected to ground during startup.
const time_t BOOT_FLAG_TIMEOUT
virtual void connectInform()
Used to notify controller that it is registered on EnigmaIOT network.
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 int FAILSAFE_RTC_ADDRESS
const int MAX_CONSECUTIVE_BOOT
virtual bool loadConfig()=0
Loads output module configuration.
EnigmaIOTNodeClass EnigmaIOTNode
void enableBroadcast(bool broadcast=true)
Enables node broadcast mode. Node will request broadcast key to Gateway. When it is received node wil...
void sleep()
Requests transition to sleep mode (low energy state)
EnigmaIOTjsonController * controller
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.
void wifiManagerExit(boolean status)
bool sendUplinkData(const uint8_t *data, size_t len, nodePayloadEncoding_t payloadEncoding, dataMessageType_t dataMsgType)
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.
void setLed(uint8_t led, time_t onTime=FLASH_LED_TIME)
Sets a LED to be flashed every time a message is transmitted.
Espnow_halClass Espnow_hal
Singleton instance of ESP-NOW class.
char * mac2str(const uint8_t *mac, char *extBuffer)
Debug helper function that generates a string that represent a MAC address.
void connectEventHandler()
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.
void onDataRx(onNodeDataRx_t handler)
Defines a function callback that will be called on every downlink data message that is received from ...