Skip to content

Commit 9c53c7a

Browse files
committed
records restart; loads node id from lsb of Si7021 serialno if not in config
1 parent b99941e commit 9c53c7a

File tree

5 files changed

+40
-6
lines changed

5 files changed

+40
-6
lines changed

SensorGridPM/SensorGridPM.ino

+1
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@ void setup() {
408408
txPower(i, DEFAULT_LORA_TX_POWER);
409409
}
410410
Watchdog.disable();
411+
recordRestart();
411412
}
412413

413414
void loop() {

SensorGridPM/config.cpp

+12-5
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ bool Config::loadConfig() {
6767
digitalWrite(default_rfm_cs, LOW);
6868
digitalWrite(alt_rfm_cs, LOW);
6969
network_id = (uint32_t)(atoi(getConfig("NETWORK_ID")));
70-
node_id = (uint8_t)(atoi(getConfig("NODE_ID")));
70+
node_id = (uint8_t)(atoi(getConfig("NODE_ID")), 0);
7171
collector_id = (uint8_t)(atoi(getConfig("COLLECTOR_ID")));
7272
rf95_freq = static_cast<float>(atof(getConfig("RF95_FREQ")));
7373
tx_power = (uint8_t)(atoi(getConfig("TX_POWER")));
@@ -87,12 +87,19 @@ bool Config::loadConfig() {
8787
logln(F("ERROR: No config file found"));
8888
return false;
8989
}
90-
WifiConfig::loadConfig();
90+
//Serial.print("Loading WiFi config .."); // TODO: collector only?
91+
//WifiConfig::loadConfig();
92+
//Serial.println(".. done");
93+
Serial.print("Loading LoRa config ..");
9194
RadioConfig::loadConfig();
92-
logln(F("Config loaded"));
95+
Serial.println(".. done");
9396
if (!node_id) {
94-
logln(F("ERROR: Missing required config parameter NODE_ID"));
95-
fail(FAIL_CODE_BAD_CONFIG);
97+
Serial.println("Node ID not configured. Using Lower byte of Si7021 serial number A.");
98+
Adafruit_Si7021 _sensor = Adafruit_Si7021();
99+
_sensor.begin();
100+
node_id = (byte)_sensor.sernum_a;
101+
Serial.print("NODE ID: ");
102+
Serial.println(node_id);
96103
}
97104
return true;
98105
}

SensorGridPM/runtime.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,16 @@ bool checkBatteryLevel() {
239239
}
240240
*/
241241

242+
void recordRestart()
243+
{
244+
println("recording restart ...");
245+
DataSample *sample = appendData();
246+
snprintf(sample->data, DATASAMPLE_DATASIZE, "{\"node\":%d,\"event\":\"restart\",\"ts\":%lu}",
247+
nodeId(), rtcz.getEpoch());
248+
recordData(sample->data, strlen(sample->data));
249+
println("done recording restart ...");
250+
}
251+
242252
void recordBatteryLevel()
243253
{
244254
// float bat = batteryLevel();

SensorGridPM/runtime.h

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ extern void recordDataSamples();
1919
extern void flashHeartbeatOn();
2020
extern void flashHeartbeatOff();
2121
extern void recordBatteryLevel();
22+
extern void recordRestart();
2223
//extern void recordTempAndHumidity();
2324
extern void recordUptime();
2425
// extern void logData(bool clear);

lib/KnightLab_Sensors/src/KL_ADAFRUIT_SI7021.cpp

+16-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,22 @@ ADAFRUIT_SI7021::~ADAFRUIT_SI7021() {}
2323
bool ADAFRUIT_SI7021::setup() {
2424
Serial.print(F("Si7021 "));
2525
if (sensor.begin()) {
26-
Serial.println(F("Found"));
26+
Serial.println(F("Found Si7021 with serial number: "));
27+
Serial.print((byte)(sensor.sernum_a >> 24), HEX);
28+
Serial.print(" ");
29+
Serial.print((byte)(sensor.sernum_a >> 16), HEX);
30+
Serial.print(" ");
31+
Serial.print((byte)(sensor.sernum_a >> 8), HEX);
32+
Serial.print(" ");
33+
Serial.print((byte)sensor.sernum_a, HEX);
34+
Serial.print(" :: ");
35+
Serial.println((byte)(sensor.sernum_b >> 24), HEX);
36+
Serial.print(" ");
37+
Serial.print((byte)(sensor.sernum_b >> 16), HEX);
38+
Serial.print(" ");
39+
Serial.print((byte)(sensor.sernum_b >> 8), HEX);
40+
Serial.print(" ");
41+
Serial.print((byte)sensor.sernum_b, HEX);
2742
return true;
2843
} else {
2944
Serial.println(F("Not Found"));

0 commit comments

Comments
 (0)