WifiEspNow
ESP-NOW Arduino library for ESP8266 and ESP32
Loading...
Searching...
No Matches
WifiEspNowBroadcast.h
Go to the documentation of this file.
1#ifndef WIFIESPNOW_BROADCAST_H
2#define WIFIESPNOW_BROADCAST_H
3
4#include "WifiEspNow.h"
5
6#include <WString.h>
7
9{
10public:
18 bool
19 begin(const char* ssid, int channel = 1, int scanFreq = 15000);
20
22 void
23 end();
24
30 void
31 loop();
32
40 bool
41 setKey(const uint8_t primary[WIFIESPNOW_KEYLEN], const uint8_t peer[WIFIESPNOW_KEYLEN] = nullptr);
42
49 void
51 {
52 WifiEspNow.onReceive(cb, arg);
53 }
54
61 bool
62 send(const uint8_t* buf, size_t count)
63 {
64 return WifiEspNow.send(nullptr, buf, count);
65 }
66
67private:
68 void
69 scan();
70
71#if defined(ARDUINO_ARCH_ESP8266)
72 static void
73 processScan(void* result, int status);
74
75 void
76 processScan2(void* result, int status);
77#elif defined(ARDUINO_ARCH_ESP32)
78 void
79 processScan();
80#endif
81
82private:
83 String m_ssid;
84 uint8_t m_peerKey[WIFIESPNOW_KEYLEN];
85 int m_scanFreq = 0;
86 unsigned long m_nextScan = 0;
87 bool m_isScanning = false;
88 bool m_hasPeerKey = false;
89};
90
101
102#endif // WIFIESPNOW_BROADCAST_H
WifiEspNowBroadcastClass WifiEspNowBroadcast
ESP-NOW pseudo broadcast.
Definition WifiEspNowBroadcast.cpp:26
WifiEspNowClass WifiEspNow
ESP-NOW API.
Definition WifiEspNow.cpp:14
Definition WifiEspNowBroadcast.h:9
bool setKey(const uint8_t primary[WIFIESPNOW_KEYLEN], const uint8_t peer[WIFIESPNOW_KEYLEN]=nullptr)
Set encryption keys.
Definition WifiEspNowBroadcast.cpp:64
void loop()
Refresh peers if scanning is due.
Definition WifiEspNowBroadcast.cpp:52
bool send(const uint8_t *buf, size_t count)
Broadcast a message.
Definition WifiEspNowBroadcast.h:62
void onReceive(WifiEspNowClass::RxCallback cb, void *arg)
Set receive callback.
Definition WifiEspNowBroadcast.h:50
bool begin(const char *ssid, int channel=1, int scanFreq=15000)
Initialize ESP-NOW with pseudo broadcast.
Definition WifiEspNowBroadcast.cpp:29
void end()
Stop ESP-NOW.
Definition WifiEspNowBroadcast.cpp:45
void onReceive(RxCallback cb, void *arg)
Set receive callback.
Definition WifiEspNow.cpp:131
void(*)(const uint8_t mac[WIFIESPNOW_ALEN], const uint8_t *buf, size_t count, void *arg) RxCallback
Definition WifiEspNow.h:103
bool send(const uint8_t mac[WIFIESPNOW_ALEN], const uint8_t *buf, size_t count)
Send a message.
Definition WifiEspNow.cpp:137