15 #define MAX_STR_LEN 1000
23 for (
int i = 0; i < len; i++) {
25 charIndex += sprintf (tempStr + charIndex,
"%02X ", buffer[i]);
31 void initWiFi (uint8_t channel,
const char* networkName,
const char* networkKey, uint8_t role) {
32 DEBUG_DBG (
"initWifi");
37 if ((err_ok = esp_wifi_set_promiscuous (
true))) {
38 DEBUG_ERROR (
"Error setting promiscuous mode: %s", esp_err_to_name (err_ok));
40 if ((err_ok = esp_wifi_set_channel (channel, WIFI_SECOND_CHAN_NONE))) {
41 DEBUG_ERROR (
"Error setting wifi channel: %s", esp_err_to_name (err_ok));
43 if ((err_ok = esp_wifi_set_promiscuous (
false))) {
44 DEBUG_ERROR (
"Error setting promiscuous mode off: %s", esp_err_to_name (err_ok));
49 wifi_set_channel (channel);
51 DEBUG_DBG (
"Mode set to STA. Channel %u", channel);
54 WiFi.softAP (networkName, networkKey, channel);
55 DEBUG_DBG (
"Mode set to AP in channel %u", channel);
58 DEBUG_INFO (
"AP MAC address of this device is %s", WiFi.softAPmacAddress ().c_str ());
59 DEBUG_INFO (
"STA MAC address of this device is %s", WiFi.macAddress ().c_str ());
64 uint32_t crc = 0xffffffff;
67 for (uint32_t i = 0x80; i > 0; i >>= 1) {
68 bool bit = crc & 0x80000000;
82 #define MACSTR "%02X:%02X:%02X:%02X:%02X:%02X"
84 char*
mac2str (
const uint8_t* mac,
char* buffer) {
87 snprintf (buffer, 18,
MACSTR, MAC2STR (mac));
94 uint8_t*
str2mac (
const char* macAddrString, uint8_t* macBytes) {
95 const char cSep =
':';
97 for (
int i = 0; i < 6; ++i) {
98 unsigned int iNumber = 0;
102 ch = tolower (*macAddrString++);
104 if ((ch < '0' || ch >
'9') && (ch < 'a' || ch >
'f')) {
112 iNumber = isdigit (ch) ? (ch -
'0') : (ch -
'a' + 10);
113 ch = tolower (*macAddrString);
115 if ((i < 5 && ch != cSep) ||
116 (i == 5 && ch !=
'\0' && !isspace (ch))) {
119 if ((ch < '0' || ch >
'9') && (ch < 'a' || ch >
'f')) {
124 iNumber += isdigit (ch) ? (ch -
'0') : (ch -
'a' + 10);
127 if (i < 5 && ch != cSep) {
132 macBytes[i] = (
unsigned char)iNumber;
140 const char* IRAM_ATTR extractFileName (
const char* path) {
143 char* p = (
char*)path;
146 if (*p ==
'/' || *p ==
'\\') {