Skip to content

Commit 62dbb0b

Browse files
authored
Merge pull request #739 from sparkfun/nsUpdates
CLI: Report the number of items in the list command
2 parents 8889cc7 + 7472d17 commit 62dbb0b

File tree

5 files changed

+94
-90
lines changed

5 files changed

+94
-90
lines changed

Firmware/RTK_Everywhere/Tasks.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2423,7 +2423,7 @@ bool tasksStartGnssUart()
24232423

24242424
availableHandlerSpace = settings.gnssHandlerBufferSize;
24252425

2426-
// Reads data from ZED and stores data into circular buffer
2426+
// Reads data from GNSS and stores data into circular buffer
24272427
if (!task.gnssReadTaskRunning)
24282428
xTaskCreatePinnedToCore(gnssReadTask, // Function to call
24292429
"gnssRead", // Just for humans

Firmware/RTK_Everywhere/menuCommands.ino

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
char otaOutcome[21] = {0}; // Modified by otaUpdate(), used to respond to rtkRemoteFirmwareVersion commands
2-
int systemWriteLength = 0; // Modified by systemWrite(), used to calculate the size of LIST command for CLI
2+
int systemWriteCounts =
3+
0; // Modified by systemWrite(), used to calculate the number of items in the LIST command for CLI
34

45
void menuCommands()
56
{
@@ -268,22 +269,16 @@ t_cliResult processCommand(char *cmdBuffer)
268269
{
269270
// Respond with a list of variables, types, and current value
270271

271-
// First calculate the size of the LIST response
272+
// First calculate the lines in the LIST response
272273
PrintEndpoint originalPrintEndpoint = printEndpoint;
273274
printEndpoint = PRINT_ENDPOINT_COUNT;
274-
systemWriteLength = 0;
275+
systemWriteCounts = 0;
275276
printAvailableSettings();
276277
printEndpoint = originalPrintEndpoint;
277278

278-
// Use log10 to find the number of digits in systemWriteLength
279-
int systemWriteLengthDigits = floor(log10(systemWriteLength)) + 1;
280-
281-
// Adjust systemWriteLength to include the length of the list entry
282-
systemWriteLength = systemWriteLength + sizeof("$SPLST,list,int,*2A") + systemWriteLengthDigits;
283-
284-
// Print the list entry
285-
char settingValue[6]; // 12345
286-
snprintf(settingValue, sizeof(settingValue), "%d", systemWriteLength);
279+
// Print the list entry with the number of items in the list, including the list entry
280+
char settingValue[6]; // 12345
281+
snprintf(settingValue, sizeof(settingValue), "%d", systemWriteCounts + 1); // Add list command
287282
commandSendExecuteListResponse("list", "int", settingValue);
288283

289284
// Now actually print the list
@@ -679,8 +674,8 @@ SettingValueResponse updateSettingWithValue(bool inCommands, const char *setting
679674
settingValue = 0;
680675

681676
bool knownSetting = false;
682-
bool settingIsString = false; // Goes true when setting needs to be surrounded by quotes during command response.
683-
// Generally char arrays but some others.
677+
bool settingIsString = false; // Goes true when setting needs to be surrounded by quotes during command
678+
// response. Generally char arrays but some others.
684679

685680
// Loop through the valid command entries
686681
i = commandLookupSettingName(inCommands, settingName, truncatedName, sizeof(truncatedName), suffix, sizeof(suffix));
@@ -807,8 +802,8 @@ SettingValueResponse updateSettingWithValue(bool inCommands, const char *setting
807802

808803
// Update the profile name in the file system if necessary
809804
if (strcmp(settingName, "profileName") == 0)
810-
setProfileName(profileNumber); // Copy the current settings.profileName into the array of profile names
811-
// at location profileNumber
805+
setProfileName(profileNumber); // Copy the current settings.profileName into the array of profile
806+
// names at location profileNumber
812807
settingIsString = true;
813808
}
814809
break;
@@ -1919,9 +1914,9 @@ void createSettingsString(char *newSettings)
19191914
break;
19201915
case tUmConst: {
19211916
// Record UM980 Constellations
1922-
// um980Constellations are uint8_t, but here we have to convert to bool (true / false) so the web page
1923-
// check boxes are populated correctly. (We can't make it bool, otherwise the 254 initializer will
1924-
// probably fail...)
1917+
// um980Constellations are uint8_t, but here we have to convert to bool (true / false) so the web
1918+
// page check boxes are populated correctly. (We can't make it bool, otherwise the 254 initializer
1919+
// will probably fail...)
19251920
for (int x = 0; x < rtkSettingsEntries[i].qualifier; x++)
19261921
{
19271922
char tempString[50]; // um980Constellations.GLONASS=true
@@ -2086,9 +2081,9 @@ void createSettingsString(char *newSettings)
20862081
break;
20872082
case tLgConst: {
20882083
// Record LG290P Constellations
2089-
// lg290pConstellations are uint8_t, but here we have to convert to bool (true / false) so the web page
2090-
// check boxes are populated correctly. (We can't make it bool, otherwise the 254 initializer will
2091-
// probably fail...)
2084+
// lg290pConstellations are uint8_t, but here we have to convert to bool (true / false) so the web
2085+
// page check boxes are populated correctly. (We can't make it bool, otherwise the 254 initializer
2086+
// will probably fail...)
20922087
for (int x = 0; x < rtkSettingsEntries[i].qualifier; x++)
20932088
{
20942089
char tempString[50]; // lg290pConstellations.GLONASS=true
@@ -2487,8 +2482,8 @@ SettingValueResponse getSettingValue(bool inCommands, const char *settingName, c
24872482
void *var;
24882483

24892484
bool knownSetting = false;
2490-
bool settingIsString = false; // Goes true when setting needs to be surrounded by quotes during command response.
2491-
// Generally char arrays but some others.
2485+
bool settingIsString = false; // Goes true when setting needs to be surrounded by quotes during command
2486+
// response. Generally char arrays but some others.
24922487

24932488
// Loop through the valid command entries - but skip the priority settings and use the GNSS-specific types
24942489
i = commandLookupSettingNameAfterPriority(inCommands, settingName, truncatedName, sizeof(truncatedName), suffix,

Firmware/RTK_Everywhere/support.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ void systemWrite(const uint8_t *buffer, uint16_t length)
6464
// We're just adding up the size of the list, don't pass along to serial port
6565
else if (printEndpoint == PRINT_ENDPOINT_COUNT)
6666
{
67-
systemWriteLength += length;
67+
systemWriteCounts++;
6868
}
6969
}
7070

Firmware/Test Sketches/ESPNOW_Receive/ESPNOW_Receive.ino

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,46 +6,58 @@
66
A receiver does not need to have the broadcastMac added to its peer list. It will receive a broadcast
77
no matter what.
88
9-
If desired, onDataRecieve should check the received MAC against the list of friendly/paired MACs
9+
If desired, onDataRecieve should check the received MAC against the list of friendly/paired MACs
1010
in order to throw out broadcasted packets that may not be valid data.
11+
12+
Add peers
13+
Add callback to deal with allowed incoming data
14+
Update test sketches
1115
*/
1216

1317
#include <esp_now.h>
14-
#include <WiFi.h>
18+
#include <esp_mac.h> //Needed for esp_read_mac()
19+
#include <WiFi.h> //Needed because ESP-NOW requires WiFi.mode()
1520

16-
void onDataRecieve(const uint8_t *mac_addr, const uint8_t *incomingData, int len)
21+
void onDataReceive(const esp_now_recv_info *mac, const uint8_t *incomingData, int len)
1722
{
18-
Serial.printf("Bytes received: %d", len);
19-
Serial.printf(" from peer: 0x%02X%02X%02X%02X%02X%02X\r\n", mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
23+
// typedef struct esp_now_recv_info {
24+
// uint8_t * src_addr; // Source address of ESPNOW packet
25+
// uint8_t * des_addr; // Destination address of ESPNOW packet
26+
// wifi_pkt_rx_ctrl_t * rx_ctrl; // Rx control info of ESPNOW packet
27+
// } esp_now_recv_info_t;
28+
29+
// Display the packet info
30+
Serial.printf(
31+
"RX from MAC %02X:%02X:%02X:%02X:%02X:%02X, %d bytes - ",
32+
mac->des_addr[0], mac->des_addr[1], mac->des_addr[2], mac->des_addr[3], mac->des_addr[4], mac->des_addr[5],
33+
len);
34+
35+
//Print what was received - it might be binary gobbly-de-gook
36+
char toPrint[len + 1];
37+
snprintf(toPrint, sizeof(toPrint), "%s", incomingData);
38+
Serial.println(toPrint);
2039
}
2140

2241
void setup()
2342
{
2443
Serial.begin(115200);
25-
delay(500);
26-
Serial.println("Point to Point Receiver - No WiFi");
44+
delay(250);
45+
Serial.println("Remote to Central - This is Central");
2746

28-
uint8_t unitMACAddress[6]; //Use MAC address in BT broadcast and display
47+
uint8_t unitMACAddress[6];
2948
esp_read_mac(unitMACAddress, ESP_MAC_WIFI_STA);
30-
Serial.print("WiFi MAC Address:");
31-
for (int x = 0 ; x < 6 ; x++)
32-
{
33-
Serial.print(" 0x");
34-
if (unitMACAddress[x] < 0x10) Serial.print("0");
35-
Serial.print(unitMACAddress[x], HEX);
36-
}
37-
Serial.println();
49+
Serial.printf("Hi! My MAC address is: {0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X}\r\n",
50+
unitMACAddress[0], unitMACAddress[1], unitMACAddress[2], unitMACAddress[3], unitMACAddress[4], unitMACAddress[5]);
3851

39-
// Set device as a Wi-Fi Station
52+
//ESP-NOW must have WiFi initialized
4053
WiFi.mode(WIFI_STA);
4154

42-
if (esp_now_init() != ESP_OK) {
55+
if (esp_now_init() != ESP_OK)
4356
Serial.println("Error initializing ESP-NOW");
44-
return;
45-
}
46-
47-
esp_now_register_recv_cb(onDataRecieve);
57+
else
58+
Serial.println("ESP-NOW started");
4859

60+
esp_now_register_recv_cb(onDataReceive);
4961
}
5062

5163
void loop()
@@ -63,26 +75,19 @@ void loop()
6375

6476
// Add a given MAC address to the peer list
6577
esp_err_t espnowAddPeer(uint8_t *peerMac)
66-
{
67-
return (espnowAddPeer(peerMac, true)); // Encrypt by default
68-
}
69-
70-
esp_err_t espnowAddPeer(uint8_t *peerMac, bool encrypt)
7178
{
7279
esp_now_peer_info_t peerInfo;
7380

7481
memcpy(peerInfo.peer_addr, peerMac, 6);
7582
peerInfo.channel = 0;
7683
peerInfo.ifidx = WIFI_IF_STA;
77-
// memcpy(peerInfo.lmk, "RTKProductsLMK56", 16);
78-
// peerInfo.encrypt = encrypt;
7984
peerInfo.encrypt = false;
8085

8186
esp_err_t result = esp_now_add_peer(&peerInfo);
8287
if (result != ESP_OK)
83-
{
84-
Serial.printf("Failed to add peer: 0x%02X%02X%02X%02X%02X%02X\r\n", peerMac[0], peerMac[1], peerMac[2],
85-
peerMac[3], peerMac[4], peerMac[5]);
86-
}
88+
Serial.printf("Failed to add peer: 0x%02X%02X%02X%02X%02X%02X\r\n", peerMac[0], peerMac[1], peerMac[2], peerMac[3], peerMac[4], peerMac[5]);
89+
else
90+
Serial.printf("Added peer: 0x%02X%02X%02X%02X%02X%02X\r\n", peerMac[0], peerMac[1], peerMac[2], peerMac[3], peerMac[4], peerMac[5]);
91+
8792
return (result);
8893
}
Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,32 @@
11
/*
2-
Transmit dummy data over ESP-NOW
2+
ESP-NOW tranmit to a specific peer
3+
By: Nathan Seidle
4+
SparkFun Electronics
5+
Date: September 25th, 2025
6+
License: Public domain / don't care.
37
4-
In this example, we don't have a paired MAC, this example simply broadcasts.
8+
In this example we transmit 'hello world' to a specified peer.
59
6-
To send a broadcast, the 0xFF broadcastMac has to be added to the peer list, *and*
7-
we have to address the message to the broadcastMac, *not* 0 to send to all peers on the list.
10+
Run ESPNOW_Transmit and ESPNOW_Recieve on two ESP32s. This example uses Broadcast ESP-NOW
11+
so no MAC addresses should be needed. ESP-NOW communication should flow correctly between the two units.
12+
13+
If you assign a remote MAC, once data is flowing, hold the remote in reset to see the delivery failures.
814
9-
A receiver does not need to have the broadcastMac added to its peer list. It will receive a broadcast
10-
no matter what.
1115
*/
1216

1317
#include <esp_now.h>
14-
#include <WiFi.h>
18+
#include <esp_mac.h> //Needed for esp_read_mac()
19+
#include <WiFi.h> //Needed because ESP-NOW requires WiFi.mode()
1520

1621
uint8_t broadcastMac[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
17-
uint8_t roverMac[] = {0x64, 0xB7, 0x08, 0x3D, 0xFD, 0xAC};
22+
uint8_t remoteMac[] = {0xB8, 0xD6, 0x1A, 0x0C, 0xA3, 0xDC}; //Modify this with the MAC address of the remote unit you want to transmit to
1823
uint8_t mockMac[] = {0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF}; //Dummy MAC for testing
1924

20-
esp_now_peer_info_t peerInfo;
21-
2225
unsigned long lastSend = 0;
2326

27+
int channelNumber = 0;
28+
uint8_t packetCounter = 0; // Intentionally 8-bit so it rolls over
29+
2430
void onDataSent(const uint8_t *mac_addr, esp_now_send_status_t status)
2531
{
2632
Serial.print("Last Packet Send Status: ");
@@ -33,9 +39,15 @@ void onDataSent(const uint8_t *mac_addr, esp_now_send_status_t status)
3339
void setup()
3440
{
3541
Serial.begin(115200);
36-
delay(500);
37-
Serial.println("Point to Point - Base Transmitter");
42+
delay(250);
43+
Serial.println("Remote to Central - This is Remote Transmitter");
44+
45+
uint8_t unitMACAddress[6];
46+
esp_read_mac(unitMACAddress, ESP_MAC_WIFI_STA);
47+
Serial.printf("Hi! My MAC address is: {0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X}\r\n",
48+
unitMACAddress[0], unitMACAddress[1], unitMACAddress[2], unitMACAddress[3], unitMACAddress[4], unitMACAddress[5]);
3849

50+
//ESP-NOW must have WiFi initialized
3951
WiFi.mode(WIFI_STA);
4052

4153
if (esp_now_init() != ESP_OK) {
@@ -45,27 +57,28 @@ void setup()
4557

4658
esp_now_register_send_cb(onDataSent);
4759

48-
//espnowAddPeer(roverMac); // Register a remote address if we want to deliver data there
60+
//espnowAddPeer(remoteMac); // Register a remote address to deliver data to
4961
espnowAddPeer(mockMac);
50-
espnowAddPeer(broadcastMac);
62+
espnowAddPeer(broadcastMac); //Remote this line to remove broadcast transmissions
5163
}
5264

5365
void loop()
5466
{
55-
if (millis() - lastSend > 500)
67+
if (millis() - lastSend > 1000)
5668
{
5769
lastSend = millis();
5870

59-
uint8_t espnowData[] = "This is the test string.";
71+
char espnowData[100];
72+
sprintf(espnowData, "This is test #: %d", packetCounter++);
6073

6174
esp_err_t result = ESP_OK;
6275

63-
result = esp_now_send(0, (uint8_t *)&espnowData, sizeof(espnowData)); // Send packet to all peers on the list, excluding broadcast peer.
64-
//result = esp_now_send(broadcastMac, (uint8_t *)&espnowData, sizeof(espnowData)); // Send packet over broadcast
65-
//result = esp_now_send(roverMac, (uint8_t *)&espnowData, sizeof(espnowData)); // Send packet to a specific peer
76+
//result = esp_now_send(0, (uint8_t *)&espnowData, strlen(espnowData)); // Send packet to all peers on the list, excluding broadcast peer.
77+
//result = esp_now_send(broadcastMac, (uint8_t *)&espnowData, strlen(espnowData)); // Send packet over broadcast
78+
result = esp_now_send(remoteMac, (uint8_t *)&espnowData, strlen(espnowData)); // Send packet to a specific peer
6679

6780
if (result == ESP_OK)
68-
Serial.println("Sent with success");
81+
Serial.println("Sent with success"); // We will always get a success with broadcastMac packets, presumably because they do not have delivery confirmation.
6982
else
7083
Serial.println("Error sending the data");
7184
}
@@ -81,28 +94,19 @@ void loop()
8194
}
8295
}
8396

84-
// Add a given MAC address to the peer list
8597
esp_err_t espnowAddPeer(uint8_t *peerMac)
86-
{
87-
return (espnowAddPeer(peerMac, true)); // Encrypt by default
88-
}
89-
90-
esp_err_t espnowAddPeer(uint8_t *peerMac, bool encrypt)
9198
{
9299
esp_now_peer_info_t peerInfo;
93100

94101
memcpy(peerInfo.peer_addr, peerMac, 6);
95102
peerInfo.channel = 0;
96103
peerInfo.ifidx = WIFI_IF_STA;
97-
// memcpy(peerInfo.lmk, "RTKProductsLMK56", 16);
98-
// peerInfo.encrypt = encrypt;
99104
peerInfo.encrypt = false;
100105

101106
esp_err_t result = esp_now_add_peer(&peerInfo);
102107
if (result != ESP_OK)
103108
{
104-
Serial.printf("Failed to add peer: 0x%02X%02X%02X%02X%02X%02X\r\n", peerMac[0], peerMac[1], peerMac[2],
105-
peerMac[3], peerMac[4], peerMac[5]);
109+
Serial.printf("Failed to add peer: 0x%02X%02X%02X%02X%02X%02X\r\n", peerMac[0], peerMac[1], peerMac[2], peerMac[3], peerMac[4], peerMac[5]);
106110
}
107111
return (result);
108-
}
112+
}

0 commit comments

Comments
 (0)