|
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>
31 #include <driver/adc.h>
34 #include <ArduinoJson.h>
35 #include <Curve25519.h>
36 #include <ESPAsyncWebServer.h>
37 #include <ESPAsyncWiFiManager.h>
38 #include <DNSServer.h>
40 #define SLEEPY 0 // Set it to 1 if your node should sleep after sending data
43 #define LED_BUILTIN 2 // ESP32 boards normally have a LED in GPIO3 or GPIO5
44 #endif // !LED_BUILTIN
47 #define USE_SERIAL // Don't forget to set DEBUG_LEVEL to NONE if serial is disabled
49 #define BLUE_LED LED_BUILTIN // You can set a different LED pin here. -1 means disabled
53 #define RESET_PIN 5 // You can set a different configuration reset pin here. Check for conflicts with used pins.
62 DEBUG_WARN (
"Connected");
68 DEBUG_WARN (
"Disconnected. Reason %d", reason);
85 DEBUG_INFO (
"Command processed");
87 DEBUG_WARN (
"Command error");
104 Serial.begin (921600);
109 if (FailSafe.isActive ()) {
126 DEBUG_WARN (
"Error reading config file");
127 if (FILESYSTEM.format ())
128 DEBUG_WARN (
"Filesystem Formatted");
136 if (wifi_get_macaddr (STATION_IF, macAddress))
138 if ((esp_wifi_get_mac (WIFI_IF_STA, macAddress) == ESP_OK))
142 DEBUG_DBG (
"Node address set to %s",
mac2str (macAddress));
144 DEBUG_WARN (
"Node address error");
154 DEBUG_DBG (
"END setup");
160 if (FailSafe.isActive ()) {
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 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 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.
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)
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.
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.
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.
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.
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 ...