EnigmaIOT  0.9.3
Secure sensor and gateway platform based on ESP8266 and ESP32
espnow_hal.h
Go to the documentation of this file.
1 
9 #ifndef _ESPNOW_HAL_h
10 #define _ESPNOW_HAL_h
11 
12 #if defined(ARDUINO) && ARDUINO >= 100
13 #include "Arduino.h"
14 #else
15 #include "WProgram.h"
16 #endif
17 
18 #if defined(ESP8266)
19 #include <ESP8266WiFi.h>
20 #elif defined(ESP32)
21 #include <WiFi.h>
22 #include <esp_now.h>
23 #endif
24 #include "Comms_hal.h"
25 #include "helperFunctions.h"
26 #include "debug.h"
27 
32 public:
33  static const size_t COMMS_HAL_MAX_MESSAGE_LENGTH = 250;
34  static const uint8_t COMMS_HAL_ADDR_LEN = 6;
35 
36 protected:
37 
39  uint8_t channel;
40 
43 
48  void initComms (peerType_t peerType);
49 
56  static void ICACHE_FLASH_ATTR rx_cb (uint8_t* mac_addr, uint8_t* data, uint8_t len);
57 
63  static void ICACHE_FLASH_ATTR tx_cb (uint8_t* mac_addr, uint8_t status);
64 
65 public:
72  void begin (uint8_t* gateway, uint8_t channel = 0, peerType_t peerType = COMM_NODE);
73 
77  void stop ();
78 
86  int32_t send (uint8_t* da, uint8_t* data, int len);
92 
98 
103  uint8_t getAddressLength () {
104  return COMMS_HAL_ADDR_LEN;
105  }
106 
113  }
114 
115 };
116 
118 
119 #endif
120 
peerType_t
peerType_t
Peer role on communication.
Definition: Comms_hal.h:22
Espnow_halClass::onDataRcvd
void onDataRcvd(comms_hal_rcvd_data dataRcvd)
Attach a callback function to be run on every received message.
Definition: espnow_hal.cpp:122
Espnow_halClass::COMMS_HAL_MAX_MESSAGE_LENGTH
static const size_t COMMS_HAL_MAX_MESSAGE_LENGTH
Maximum message length for ESP-NOW.
Definition: espnow_hal.h:33
Espnow_halClass::send
int32_t send(uint8_t *da, uint8_t *data, int len)
Sends data to the other peer.
Definition: espnow_hal.cpp:86
Espnow_halClass::dataRcvd
comms_hal_rcvd_data dataRcvd
Pointer to a function to be called on every received message.
Definition: espnow_hal.h:41
Espnow_halClass::gateway
uint8_t gateway[COMMS_HAL_ADDR_LEN]
Gateway address.
Definition: espnow_hal.h:38
Espnow_halClass
Definition for ESP-NOW hardware abstraction layer.
Definition: espnow_hal.h:31
Espnow_halClass::getAddressLength
uint8_t getAddressLength()
Get address length used on ESP-NOW subsystem.
Definition: espnow_hal.h:103
Espnow_halClass::tx_cb
static void ICACHE_FLASH_ATTR tx_cb(uint8_t *mac_addr, uint8_t status)
Function that gets sending status.
Definition: espnow_hal.cpp:61
Espnow_halClass::onDataSent
void onDataSent(comms_hal_sent_data dataRcvd)
Attach a callback function to be run after sending a message to receive its status.
Definition: espnow_hal.cpp:126
Espnow_halClass::rx_cb
static void ICACHE_FLASH_ATTR rx_cb(uint8_t *mac_addr, uint8_t *data, uint8_t len)
Function that processes incoming messages and passes them to upper layer.
Definition: espnow_hal.cpp:55
Espnow_halClass::stop
void stop()
Terminates communication and closes all connectrions.
Definition: espnow_hal.cpp:79
Espnow_halClass::channel
uint8_t channel
WiFi channel to be used.
Definition: espnow_hal.h:39
COMM_NODE
@ COMM_NODE
Definition: Comms_hal.h:23
comms_hal_rcvd_data
void(* comms_hal_rcvd_data)(uint8_t *address, uint8_t *data, uint8_t len)
Definition: Comms_hal.h:27
Espnow_hal
Espnow_halClass Espnow_hal
Singleton instance of ESP-NOW class.
Definition: espnow_hal.cpp:20
Espnow_halClass::begin
void begin(uint8_t *gateway, uint8_t channel=0, peerType_t peerType=COMM_NODE)
Setup communication environment and establish the connection from node to gateway.
Definition: espnow_hal.cpp:67
data
@ data
Definition: GwOutput_generic.h:23
Espnow_halClass::initComms
void initComms(peerType_t peerType)
Communication subsistem initialization.
Definition: espnow_hal.cpp:24
helperFunctions.h
Auxiliary function definition.
Espnow_halClass::getMaxMessageLength
size_t getMaxMessageLength()
Get maximum message length on ESP-NOW subsystem.
Definition: espnow_hal.h:111
Espnow_halClass::sentResult
comms_hal_sent_data sentResult
Pointer to a function to be called to notify last sending status.
Definition: espnow_hal.h:42
Comms_hal.h
Generic communication system abstraction layer.
comms_hal_sent_data
void(* comms_hal_sent_data)(uint8_t *address, uint8_t status)
Definition: Comms_hal.h:28
status
@ status
Definition: GwOutput_generic.h:25
Comms_halClass
Interface for communication subsystem abstraction layer definition.
Definition: Comms_hal.h:33
debug.h
Auxiliary functions for debugging over Serial.
Espnow_halClass::COMMS_HAL_ADDR_LEN
static const uint8_t COMMS_HAL_ADDR_LEN
Address length for ESP-NOW. Correspond to mac address.
Definition: espnow_hal.h:34