Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Firmware/RTK_Everywhere/Tasks.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2423,7 +2423,7 @@ bool tasksStartGnssUart()

availableHandlerSpace = settings.gnssHandlerBufferSize;

// Reads data from ZED and stores data into circular buffer
// Reads data from GNSS and stores data into circular buffer
if (!task.gnssReadTaskRunning)
xTaskCreatePinnedToCore(gnssReadTask, // Function to call
"gnssRead", // Just for humans
Expand Down
43 changes: 19 additions & 24 deletions Firmware/RTK_Everywhere/menuCommands.ino
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
char otaOutcome[21] = {0}; // Modified by otaUpdate(), used to respond to rtkRemoteFirmwareVersion commands
int systemWriteLength = 0; // Modified by systemWrite(), used to calculate the size of LIST command for CLI
int systemWriteCounts =
0; // Modified by systemWrite(), used to calculate the number of items in the LIST command for CLI

void menuCommands()
{
Expand Down Expand Up @@ -268,22 +269,16 @@ t_cliResult processCommand(char *cmdBuffer)
{
// Respond with a list of variables, types, and current value

// First calculate the size of the LIST response
// First calculate the lines in the LIST response
PrintEndpoint originalPrintEndpoint = printEndpoint;
printEndpoint = PRINT_ENDPOINT_COUNT;
systemWriteLength = 0;
systemWriteCounts = 0;
printAvailableSettings();
printEndpoint = originalPrintEndpoint;

// Use log10 to find the number of digits in systemWriteLength
int systemWriteLengthDigits = floor(log10(systemWriteLength)) + 1;

// Adjust systemWriteLength to include the length of the list entry
systemWriteLength = systemWriteLength + sizeof("$SPLST,list,int,*2A") + systemWriteLengthDigits;

// Print the list entry
char settingValue[6]; // 12345
snprintf(settingValue, sizeof(settingValue), "%d", systemWriteLength);
// Print the list entry with the number of items in the list, including the list entry
char settingValue[6]; // 12345
snprintf(settingValue, sizeof(settingValue), "%d", systemWriteCounts + 1); // Add list command
commandSendExecuteListResponse("list", "int", settingValue);

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

bool knownSetting = false;
bool settingIsString = false; // Goes true when setting needs to be surrounded by quotes during command response.
// Generally char arrays but some others.
bool settingIsString = false; // Goes true when setting needs to be surrounded by quotes during command
// response. Generally char arrays but some others.

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

// Update the profile name in the file system if necessary
if (strcmp(settingName, "profileName") == 0)
setProfileName(profileNumber); // Copy the current settings.profileName into the array of profile names
// at location profileNumber
setProfileName(profileNumber); // Copy the current settings.profileName into the array of profile
// names at location profileNumber
settingIsString = true;
}
break;
Expand Down Expand Up @@ -1919,9 +1914,9 @@ void createSettingsString(char *newSettings)
break;
case tUmConst: {
// Record UM980 Constellations
// um980Constellations are uint8_t, but here we have to convert to bool (true / false) so the web page
// check boxes are populated correctly. (We can't make it bool, otherwise the 254 initializer will
// probably fail...)
// um980Constellations are uint8_t, but here we have to convert to bool (true / false) so the web
// page check boxes are populated correctly. (We can't make it bool, otherwise the 254 initializer
// will probably fail...)
for (int x = 0; x < rtkSettingsEntries[i].qualifier; x++)
{
char tempString[50]; // um980Constellations.GLONASS=true
Expand Down Expand Up @@ -2086,9 +2081,9 @@ void createSettingsString(char *newSettings)
break;
case tLgConst: {
// Record LG290P Constellations
// lg290pConstellations are uint8_t, but here we have to convert to bool (true / false) so the web page
// check boxes are populated correctly. (We can't make it bool, otherwise the 254 initializer will
// probably fail...)
// lg290pConstellations are uint8_t, but here we have to convert to bool (true / false) so the web
// page check boxes are populated correctly. (We can't make it bool, otherwise the 254 initializer
// will probably fail...)
for (int x = 0; x < rtkSettingsEntries[i].qualifier; x++)
{
char tempString[50]; // lg290pConstellations.GLONASS=true
Expand Down Expand Up @@ -2487,8 +2482,8 @@ SettingValueResponse getSettingValue(bool inCommands, const char *settingName, c
void *var;

bool knownSetting = false;
bool settingIsString = false; // Goes true when setting needs to be surrounded by quotes during command response.
// Generally char arrays but some others.
bool settingIsString = false; // Goes true when setting needs to be surrounded by quotes during command
// response. Generally char arrays but some others.

// Loop through the valid command entries - but skip the priority settings and use the GNSS-specific types
i = commandLookupSettingNameAfterPriority(inCommands, settingName, truncatedName, sizeof(truncatedName), suffix,
Expand Down
2 changes: 1 addition & 1 deletion Firmware/RTK_Everywhere/support.ino
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void systemWrite(const uint8_t *buffer, uint16_t length)
// We're just adding up the size of the list, don't pass along to serial port
else if (printEndpoint == PRINT_ENDPOINT_COUNT)
{
systemWriteLength += length;
systemWriteCounts++;
}
}

Expand Down
71 changes: 38 additions & 33 deletions Firmware/Test Sketches/ESPNOW_Receive/ESPNOW_Receive.ino
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,58 @@
A receiver does not need to have the broadcastMac added to its peer list. It will receive a broadcast
no matter what.

If desired, onDataRecieve should check the received MAC against the list of friendly/paired MACs
If desired, onDataRecieve should check the received MAC against the list of friendly/paired MACs
in order to throw out broadcasted packets that may not be valid data.

Add peers
Add callback to deal with allowed incoming data
Update test sketches
*/

#include <esp_now.h>
#include <WiFi.h>
#include <esp_mac.h> //Needed for esp_read_mac()
#include <WiFi.h> //Needed because ESP-NOW requires WiFi.mode()

void onDataRecieve(const uint8_t *mac_addr, const uint8_t *incomingData, int len)
void onDataReceive(const esp_now_recv_info *mac, const uint8_t *incomingData, int len)
{
Serial.printf("Bytes received: %d", len);
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]);
// typedef struct esp_now_recv_info {
// uint8_t * src_addr; // Source address of ESPNOW packet
// uint8_t * des_addr; // Destination address of ESPNOW packet
// wifi_pkt_rx_ctrl_t * rx_ctrl; // Rx control info of ESPNOW packet
// } esp_now_recv_info_t;

// Display the packet info
Serial.printf(
"RX from MAC %02X:%02X:%02X:%02X:%02X:%02X, %d bytes - ",
mac->des_addr[0], mac->des_addr[1], mac->des_addr[2], mac->des_addr[3], mac->des_addr[4], mac->des_addr[5],
len);

//Print what was received - it might be binary gobbly-de-gook
char toPrint[len + 1];
snprintf(toPrint, sizeof(toPrint), "%s", incomingData);
Serial.println(toPrint);
}

void setup()
{
Serial.begin(115200);
delay(500);
Serial.println("Point to Point Receiver - No WiFi");
delay(250);
Serial.println("Remote to Central - This is Central");

uint8_t unitMACAddress[6]; //Use MAC address in BT broadcast and display
uint8_t unitMACAddress[6];
esp_read_mac(unitMACAddress, ESP_MAC_WIFI_STA);
Serial.print("WiFi MAC Address:");
for (int x = 0 ; x < 6 ; x++)
{
Serial.print(" 0x");
if (unitMACAddress[x] < 0x10) Serial.print("0");
Serial.print(unitMACAddress[x], HEX);
}
Serial.println();
Serial.printf("Hi! My MAC address is: {0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X}\r\n",
unitMACAddress[0], unitMACAddress[1], unitMACAddress[2], unitMACAddress[3], unitMACAddress[4], unitMACAddress[5]);

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

if (esp_now_init() != ESP_OK) {
if (esp_now_init() != ESP_OK)
Serial.println("Error initializing ESP-NOW");
return;
}

esp_now_register_recv_cb(onDataRecieve);
else
Serial.println("ESP-NOW started");

esp_now_register_recv_cb(onDataReceive);
}

void loop()
Expand All @@ -63,26 +75,19 @@ void loop()

// Add a given MAC address to the peer list
esp_err_t espnowAddPeer(uint8_t *peerMac)
{
return (espnowAddPeer(peerMac, true)); // Encrypt by default
}

esp_err_t espnowAddPeer(uint8_t *peerMac, bool encrypt)
{
esp_now_peer_info_t peerInfo;

memcpy(peerInfo.peer_addr, peerMac, 6);
peerInfo.channel = 0;
peerInfo.ifidx = WIFI_IF_STA;
// memcpy(peerInfo.lmk, "RTKProductsLMK56", 16);
// peerInfo.encrypt = encrypt;
peerInfo.encrypt = false;

esp_err_t result = esp_now_add_peer(&peerInfo);
if (result != ESP_OK)
{
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]);
}
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]);
else
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]);

return (result);
}
66 changes: 35 additions & 31 deletions Firmware/Test Sketches/ESPNOW_Transmit/ESPNOW_Transmit.ino
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
/*
Transmit dummy data over ESP-NOW
ESP-NOW tranmit to a specific peer
By: Nathan Seidle
SparkFun Electronics
Date: September 25th, 2025
License: Public domain / don't care.

In this example, we don't have a paired MAC, this example simply broadcasts.
In this example we transmit 'hello world' to a specified peer.

To send a broadcast, the 0xFF broadcastMac has to be added to the peer list, *and*
we have to address the message to the broadcastMac, *not* 0 to send to all peers on the list.
Run ESPNOW_Transmit and ESPNOW_Recieve on two ESP32s. This example uses Broadcast ESP-NOW
so no MAC addresses should be needed. ESP-NOW communication should flow correctly between the two units.

If you assign a remote MAC, once data is flowing, hold the remote in reset to see the delivery failures.

A receiver does not need to have the broadcastMac added to its peer list. It will receive a broadcast
no matter what.
*/

#include <esp_now.h>
#include <WiFi.h>
#include <esp_mac.h> //Needed for esp_read_mac()
#include <WiFi.h> //Needed because ESP-NOW requires WiFi.mode()

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

esp_now_peer_info_t peerInfo;

unsigned long lastSend = 0;

int channelNumber = 0;
uint8_t packetCounter = 0; // Intentionally 8-bit so it rolls over

void onDataSent(const uint8_t *mac_addr, esp_now_send_status_t status)
{
Serial.print("Last Packet Send Status: ");
Expand All @@ -33,9 +39,15 @@ void onDataSent(const uint8_t *mac_addr, esp_now_send_status_t status)
void setup()
{
Serial.begin(115200);
delay(500);
Serial.println("Point to Point - Base Transmitter");
delay(250);
Serial.println("Remote to Central - This is Remote Transmitter");

uint8_t unitMACAddress[6];
esp_read_mac(unitMACAddress, ESP_MAC_WIFI_STA);
Serial.printf("Hi! My MAC address is: {0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X}\r\n",
unitMACAddress[0], unitMACAddress[1], unitMACAddress[2], unitMACAddress[3], unitMACAddress[4], unitMACAddress[5]);

//ESP-NOW must have WiFi initialized
WiFi.mode(WIFI_STA);

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

esp_now_register_send_cb(onDataSent);

//espnowAddPeer(roverMac); // Register a remote address if we want to deliver data there
//espnowAddPeer(remoteMac); // Register a remote address to deliver data to
espnowAddPeer(mockMac);
espnowAddPeer(broadcastMac);
espnowAddPeer(broadcastMac); //Remote this line to remove broadcast transmissions
}

void loop()
{
if (millis() - lastSend > 500)
if (millis() - lastSend > 1000)
{
lastSend = millis();

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

esp_err_t result = ESP_OK;

result = esp_now_send(0, (uint8_t *)&espnowData, sizeof(espnowData)); // Send packet to all peers on the list, excluding broadcast peer.
//result = esp_now_send(broadcastMac, (uint8_t *)&espnowData, sizeof(espnowData)); // Send packet over broadcast
//result = esp_now_send(roverMac, (uint8_t *)&espnowData, sizeof(espnowData)); // Send packet to a specific peer
//result = esp_now_send(0, (uint8_t *)&espnowData, strlen(espnowData)); // Send packet to all peers on the list, excluding broadcast peer.
//result = esp_now_send(broadcastMac, (uint8_t *)&espnowData, strlen(espnowData)); // Send packet over broadcast
result = esp_now_send(remoteMac, (uint8_t *)&espnowData, strlen(espnowData)); // Send packet to a specific peer

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

// Add a given MAC address to the peer list
esp_err_t espnowAddPeer(uint8_t *peerMac)
{
return (espnowAddPeer(peerMac, true)); // Encrypt by default
}

esp_err_t espnowAddPeer(uint8_t *peerMac, bool encrypt)
{
esp_now_peer_info_t peerInfo;

memcpy(peerInfo.peer_addr, peerMac, 6);
peerInfo.channel = 0;
peerInfo.ifidx = WIFI_IF_STA;
// memcpy(peerInfo.lmk, "RTKProductsLMK56", 16);
// peerInfo.encrypt = encrypt;
peerInfo.encrypt = false;

esp_err_t result = esp_now_add_peer(&peerInfo);
if (result != ESP_OK)
{
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]);
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]);
}
return (result);
}
}