 |
EnigmaIOT
0.9.3
Secure sensor and gateway platform based on ESP8266 and ESP32
|
Go to the documentation of this file.
25 if (esp_now_init () != 0) {
31 esp_now_set_self_role (ESP_NOW_ROLE_CONTROLLER);
34 esp_now_peer_info_t networkGw;
37 networkGw.ifidx = ESP_IF_WIFI_STA;
38 networkGw.encrypt =
false;
39 esp_err_t result = esp_now_add_peer (&networkGw);
40 DEBUG_INFO (
"Gateway peer Added in channel %d. Result = %s",
channel, esp_err_to_name(result));
41 DEBUG_DBG (
"WIFI channel is %d", WiFi.channel ());
46 esp_now_set_self_role (ESP_NOW_ROLE_SLAVE);
50 esp_now_register_recv_cb (
reinterpret_cast<esp_now_recv_cb_t
>(
rx_cb));
51 esp_now_register_send_cb (
reinterpret_cast<esp_now_send_cb_t
>(
tx_cb));
80 DEBUG_INFO (
"-------------> ESP-NOW STOP");
81 esp_now_unregister_recv_cb ();
82 esp_now_unregister_send_cb ();
90 DEBUG_DBG (
"ESP-NOW message to %s", buffer);
92 esp_now_peer_info_t peer;
95 wifi_second_chan_t secondCh;
96 esp_wifi_get_channel (&ch, &secondCh);
98 peer.ifidx = ESP_IF_WIFI_AP;
100 esp_err_t error = esp_now_add_peer (&peer);
101 DEBUG_DBG (
"Peer added on channel %u. Result %d", ch, error);
110 int32_t error = esp_now_send (da,
data, len);
112 DEBUG_DBG (
"esp now send result = %d", error);
114 esp_err_t error = esp_now_del_peer (da);
115 DEBUG_DBG (
"Peer deleted. Result %d", error);
peerType_t
Peer role on communication.
void onDataRcvd(comms_hal_rcvd_data dataRcvd)
Attach a callback function to be run on every received message.
int32_t send(uint8_t *da, uint8_t *data, int len)
Sends data to the other peer.
comms_hal_rcvd_data dataRcvd
Pointer to a function to be called on every received message.
uint8_t gateway[COMMS_HAL_ADDR_LEN]
Gateway address.
Definition for ESP-NOW hardware abstraction layer.
static void ICACHE_FLASH_ATTR tx_cb(uint8_t *mac_addr, uint8_t status)
Function that gets sending status.
void onDataSent(comms_hal_sent_data dataRcvd)
Attach a callback function to be run after sending a message to receive its status.
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.
void stop()
Terminates communication and closes all connectrions.
uint8_t channel
WiFi channel to be used.
char * mac2str(const uint8_t *mac, char *buffer)
Debug helper function that generates a string that represent a MAC address.
void(* comms_hal_rcvd_data)(uint8_t *address, uint8_t *data, uint8_t len)
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.
peerType_t _ownPeerType
Stores peer type, node or gateway.
Espnow_halClass Espnow_hal
Singleton instance of ESP-NOW class.
void initComms(peerType_t peerType)
Communication subsistem initialization.
comms_hal_sent_data sentResult
Pointer to a function to be called to notify last sending status.
void(* comms_hal_sent_data)(uint8_t *address, uint8_t status)
ESP-NOW communication system abstraction layer. To be used on ESP8266 or ESP32 platforms.
static const uint8_t COMMS_HAL_ADDR_LEN
Address length for ESP-NOW. Correspond to mac address.