|
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
24 #include <ArduinoJson.h>
27 #include <ESP8266WiFi.h>
31 #include <driver/adc.h>
34 #include <ArduinoJson.h>
37 #define SLEEPY 0 // Set it to 1 if your node should sleep after sending data
41 #define LED_BUILTIN 2 // ESP32 boards normally have a LED in GPIO3 or GPIO5
45 #define USE_SERIAL // Don't forget to set DEBUG_LEVEL to NONE if serial is disabled
47 #define BLUE_LED LED_BUILTIN // You can set a different LED pin here. -1 means disabled
51 #define RESET_PIN 13 // You can set a different configuration reset pin here. Check for conflicts with used pins.
64 DEBUG_WARN (
"Connected");
69 DEBUG_WARN (
"Disconnected. Reason %d", reason);
86 DEBUG_INFO (
"Command processed");
88 DEBUG_WARN (
"Command error");
105 Serial.begin (921600);
111 if (FailSafe.isActive ()) {
128 DEBUG_WARN (
"Error reading config file");
129 if (FILESYSTEM.format ())
130 DEBUG_WARN (
"File System Formatted");
141 if (wifi_get_macaddr (STATION_IF, macAddress))
143 if ((esp_wifi_get_mac (WIFI_IF_STA, macAddress) == ESP_OK))
147 DEBUG_DBG (
"Node address set to %s",
mac2str (macAddress));
149 DEBUG_WARN (
"Node address error");
159 DEBUG_DBG (
"END setup");
165 if (FailSafe.isActive ()) {
170 #if SUPPORT_HA_DISCOVERY
172 #endif // SUPPORT_HA_DISCOVERY
176 FailSafe.resetFlag ();
virtual void loop()=0
This should be called periodically for module handling.
const int FAILSAFE_RTC_ADDRESS
EnigmaIOTjsonController * controller
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 disconnectEventHandler(nodeInvalidateReason_t reason)
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.
const time_t BOOT_FLAG_TIMEOUT
void connectEventHandler()
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 wifiManagerStarted()
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 wifiManagerExit(bool status)
void setLed(uint8_t led, time_t onTime=FLASH_LED_TIME)
Sets a LED to be flashed every time a message is transmitted.
void processRxData(const uint8_t *mac, const uint8_t *buffer, uint8_t length, nodeMessageType_t command, nodePayloadEncoding_t payloadEncoding)
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.
const int MAX_CONSECUTIVE_BOOT
Prototype for JSON/MSGPACK based controller node.
bool sendUplinkData(const uint8_t *data, size_t len, nodePayloadEncoding_t payloadEncoding, dataMessageType_t dataMsgType)
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 ...