Skip to content

Commit b0461be

Browse files
committed
Now checking for NTP errors.
Fixed include copy/paste errors in SPIFFS CLI command. Skip trying to upload empty message files, fixed truncation of lines when catting SPIFFS files, fixed a CLI help typo.
1 parent acae023 commit b0461be

4 files changed

Lines changed: 38 additions & 12 deletions

File tree

firmware/wombat/src/cli/CLI.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,15 @@ static const CLI_Command_Definition_t powerCmd = {
8484
//! SD card commands
8585
static const CLI_Command_Definition_t sdCmd = {
8686
CLISDCard::cmd.c_str(),
87-
"sd:\r\n Access the SD card\r\n",
87+
"sd rm|data|log:\r\n Access the SD card\r\n",
8888
CLISDCard::enter_cli,
8989
-1
9090
};
9191

9292
//! SPIFFS commands
9393
static const CLI_Command_Definition_t spiffsCmd = {
9494
CLISPIFFS::cmd.c_str(),
95-
"sd:\r\n Access the SPIFFS filesystem\r\n",
95+
"spiffs ls|cat|cp|rm:\r\n Access the SPIFFS filesystem\r\n",
9696
CLISPIFFS::enter_cli,
9797
-1
9898
};

firmware/wombat/src/cli/peripherals/cli_spiffs.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,11 @@
55
*/
66
#include <SPIFFS.h>
77

8-
#include "cli/peripherals/sd_card.h"
9-
108
#include <freertos/FreeRTOS.h>
119
#include <Stream.h>
1210

1311
#include "cli/FreeRTOS_CLI.h"
1412

15-
#include "globals.h"
16-
#include "sd-card/interface.h"
1713
#include "cli/CLI.h"
1814
#include "cli/peripherals/cli_spiffs.h"
1915
#include "Utils.h"
@@ -53,7 +49,7 @@ BaseType_t CLISPIFFS::enter_cli(char *pcWriteBuffer, size_t xWriteBufferLen, con
5349

5450
// readBytesUntil strips the delimiter, so put the '\n' back in.
5551
if (len <= xWriteBufferLen) {
56-
pcWriteBuffer[len-1] = '\n';
52+
pcWriteBuffer[len] = '\n';
5753
}
5854

5955
return response_buffer_.available() > 0 ? pdTRUE : pdFALSE;

firmware/wombat/src/ntp.cpp

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ bool getNTPTime(SARA_R5 &r5) {
3131
memset(packetBuffer, 0, NTP_PACKET_SIZE);
3232

3333
// Initialize values needed to form NTP request. The client request only needs to set version numbers & mode.
34-
packetBuffer[0] = 0b11100011; // LI, Version, Mode
35-
34+
packetBuffer[0] = 0b00000000; // LI 0
35+
packetBuffer[0] |= 0b00100000; // Version 4
36+
packetBuffer[0] |= 0b00000011; // Mode 3, client
3637
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
3738

3839
// Allocate a UDP socket to talk to the NTP server
@@ -64,7 +65,7 @@ bool getNTPTime(SARA_R5 &r5) {
6465
if (r5.socketReadAvailableUDP(socketNum, &avail) != SARA_R5_SUCCESS) {
6566
ESP_LOGE(TAG, "socketReadAvailable failed");
6667
r5.socketClose(socketNum);
67-
return (false);
68+
return false;
6869
}
6970

7071
if (avail >= NTP_PACKET_SIZE) {
@@ -75,11 +76,14 @@ bool getNTPTime(SARA_R5 &r5) {
7576
if (r5.socketReadUDP(socketNum, NTP_PACKET_SIZE, (char *)&packetBuffer) != SARA_R5_SUCCESS) {
7677
ESP_LOGE(TAG, "socketRead failed");
7778
r5.socketClose(socketNum); // Be nice. Close the socket
78-
return (false);
79+
return false;
7980
}
8081

82+
Serial.println();
83+
Serial.println("NTP response");
84+
8185
int x = 0;
82-
char hexbuf[4];
86+
char hexbuf[5]; // Also used to print reference id field, so 5 long.
8387
while (x < NTP_PACKET_SIZE) {
8488
snprintf(hexbuf, sizeof(hexbuf), "%02X ", packetBuffer[x++]);
8589
Serial.print(hexbuf);
@@ -98,6 +102,24 @@ bool getNTPTime(SARA_R5 &r5) {
98102
40: E7 8B F8 61 6B 17 F3 80
99103
100104
*/
105+
106+
// A stratum value of 0 or 1 means a reference id field will also be present, so print that out for
107+
// debugging, and if statum is 0, do not try to set the time because that's an error indicator.
108+
if (packetBuffer[1] < 2) {
109+
hexbuf[0] = packetBuffer[12];
110+
hexbuf[1] = packetBuffer[13];
111+
hexbuf[2] = packetBuffer[14];
112+
hexbuf[3] = packetBuffer[15];
113+
hexbuf[4] = 0;
114+
115+
ESP_LOGI(TAG, "NTP Ref Id: %s", hexbuf);
116+
117+
if (packetBuffer[1] == 0) {
118+
ESP_LOGE(TAG, "NTP KoD");
119+
return false;
120+
}
121+
}
122+
101123
// Extract the time from the reply
102124

103125
// The timestamp starts at byte 40 of the received packet and is a uint32_t value.

firmware/wombat/src/uplinks.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ static bool process_file(const String& filename) {
3737
return false;
3838
}
3939

40+
// Found that on a Wombat with an extended comms outage the SPIFFS FS can fill
41+
// up, but maybe still have room for directory entries leading to empty files.
42+
// Just delete the file and move on.
43+
if (msg_len < 1) {
44+
SPIFFS.remove(filename);
45+
return true;
46+
}
47+
4048
if (mqtt_status == MQTT_UNINITIALISED) {
4149
if ( ! connect_to_internet()) {
4250
ESP_LOGE(TAG, "cti failed, not processing file");

0 commit comments

Comments
 (0)