Skip to content

Commit f0f574a

Browse files
committed
[SD] ds18x20 decode thru controller via HandleAdd OK
1 parent bf7b7de commit f0f574a

File tree

3 files changed

+83
-30
lines changed

3 files changed

+83
-30
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# 1 "/var/folders/ff/dmzflvf52tq9kzvt6g8jglxw0000gn/T/tmpi83fbtc8"
2+
#include <Arduino.h>
3+
# 1 "/Users/brentrubell/Documents/Arduino/libraries/Adafruit_Wippersnapper_Arduino/src/Wippersnapper_demo_wokwi.ino"
4+
# 14 "/Users/brentrubell/Documents/Arduino/libraries/Adafruit_Wippersnapper_Arduino/src/Wippersnapper_demo_wokwi.ino"
5+
#define IO_USERNAME "brubell"
6+
#define IO_KEY "YOUR_AIO_KEY"
7+
8+
#define WIFI_SSID "Wokwi-GUEST"
9+
#define WIFI_PASS ""
10+
11+
#define WS_DEBUG
12+
13+
#define API_PIN 0
14+
15+
#include "ws_manager.h"
16+
17+
18+
Wippersnapper_Manager manager;
19+
Wippersnapper_WiFiV2 wipper(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, "io.adafruit.com", 8883);
20+
void setup();
21+
void loop();
22+
#line 31 "/Users/brentrubell/Documents/Arduino/libraries/Adafruit_Wippersnapper_Arduino/src/Wippersnapper_demo_wokwi.ino"
23+
void setup() {
24+
25+
manager.checkAPIVersion(API_PIN);
26+
manager.provision();
27+
28+
Serial.begin(115200);
29+
30+
Serial.println("Adafruit Wippersnapper API Manager Demo");
31+
Serial.print("Running Wippersnapper API Version: ");
32+
Serial.println(manager.getAPIVersion());
33+
manager.connect();
34+
}
35+
36+
void loop() {
37+
manager.run();
38+
}

src/components/ds18x20/controller.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,19 +102,21 @@ bool DS18X20Controller::Handle_Ds18x20Add(pb_istream_t *stream) {
102102
is_initialized = false;
103103
}
104104

105-
// Encode and publish a Ds18x20Added message back to the broker
106-
unsigned long encode_start_time = millis();
107-
if (!_DS18X20_model->EncodeDS18x20Added(
108-
_DS18X20_model->GetDS18x20AddMsg()->onewire_pin, is_initialized)) {
109-
WS_DEBUG_PRINTLN("ERROR | DS18x20: Unable to encode Ds18x20Added message!");
110-
return false;
111-
}
105+
// If we're not in offline mode, publish a Ds18x20Added message back to the broker
106+
if (! WsV2._sdCardV2->mode_offline) {
107+
// Encode and publish a Ds18x20Added message back to the broker
108+
if (!_DS18X20_model->EncodeDS18x20Added(
109+
_DS18X20_model->GetDS18x20AddMsg()->onewire_pin, is_initialized)) {
110+
WS_DEBUG_PRINTLN("ERROR | DS18x20: Unable to encode Ds18x20Added message!");
111+
return false;
112+
}
112113

113-
if (!WsV2.PublishSignal(wippersnapper_signal_DeviceToBroker_ds18x20_added_tag,
114-
_DS18X20_model->GetDS18x20AddedMsg())) {
115-
WS_DEBUG_PRINTLN(
116-
"ERROR | DS18x20: Unable to publish Ds18x20Added message!");
117-
return false;
114+
if (!WsV2.PublishSignal(wippersnapper_signal_DeviceToBroker_ds18x20_added_tag,
115+
_DS18X20_model->GetDS18x20AddedMsg())) {
116+
WS_DEBUG_PRINTLN(
117+
"ERROR | DS18x20: Unable to publish Ds18x20Added message!");
118+
return false;
119+
}
118120
}
119121

120122
return true;

src/provisioning/sdcard/ws_sdcard.cpp

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -305,30 +305,43 @@ bool ws_sdcard::parseConfigFile() {
305305
return false;
306306
}
307307

308+
WS_DEBUG_PRINT("[SD] msg_DS18X20Add.sensor_types_count: ");
309+
WS_DEBUG_PRINTLN(msg_DS18X20Add.sensor_types_count);
310+
308311
// Parse the sensor types into the DS18X20Add message
309312
// TODO: This structor needs a refactoring pass! It's too confusing
310-
if (msg_DS18X20Add.sensor_types_count == 1) {
311-
if (component["sensorType1"] != nullptr) {
312-
msg_DS18X20Add.sensor_types[0] = component["sensorType1"];
313+
if (msg_DS18X20Add.sensor_types_count == 1 ||
314+
msg_DS18X20Add.sensor_types_count == 2) {
315+
if (strcmp(component["sensorType1"], "ambient-temp-fahrenheit") == 0) {
316+
msg_DS18X20Add.sensor_types[0] =
317+
wippersnapper_sensor_SensorType_SENSOR_TYPE_OBJECT_TEMPERATURE_FAHRENHEIT;
318+
} else if (strcmp(component["sensorType1"], "ambient-temp") == 0) {
319+
msg_DS18X20Add.sensor_types[0] =
320+
wippersnapper_sensor_SensorType_SENSOR_TYPE_OBJECT_TEMPERATURE;
313321
} else {
314-
WS_DEBUG_PRINTLN("[SD] FATAL Parsing error - No sensor type found in "
315-
"JSON string!");
322+
WS_DEBUG_PRINTLN(
323+
"[SD] FATAL Parsing error - Unsupported ds18x sensor "
324+
"type found in JSON!");
316325
return false;
317326
}
318-
} else if (msg_DS18X20Add.sensor_types_count == 2) {
319-
if (component["sensorType1"] != nullptr &&
320-
component["sensorType2"] != nullptr) {
321-
msg_DS18X20Add.sensor_types[0] = component["sensorType1"];
322-
msg_DS18X20Add.sensor_types[1] = component["sensorType2"];
323-
} else {
324-
WS_DEBUG_PRINTLN("[SD] FATAL Parsing error - No sensor type found in "
325-
"JSON string!");
326-
return false;
327+
}
328+
if (msg_DS18X20Add.sensor_types_count == 2) {
329+
WS_DEBUG_PRINTLN("[SD] Parsing sensor type 2...");
330+
if (component["sensorType2"] != nullptr) {
331+
if (strcmp(component["sensorType2"], "ambient-temp-fahrenheit") ==
332+
0) {
333+
msg_DS18X20Add.sensor_types[1] =
334+
wippersnapper_sensor_SensorType_SENSOR_TYPE_OBJECT_TEMPERATURE_FAHRENHEIT;
335+
} else if (strcmp(component["sensorType2"], "ambient-temp") == 0) {
336+
msg_DS18X20Add.sensor_types[1] =
337+
wippersnapper_sensor_SensorType_SENSOR_TYPE_OBJECT_TEMPERATURE;
338+
} else {
339+
WS_DEBUG_PRINTLN(
340+
"[SD] FATAL Parsing error - Unsupported ds18x sensor "
341+
"type found in JSON!");
342+
return false;
343+
}
327344
}
328-
} else {
329-
WS_DEBUG_PRINTLN("[SD] FATAL Parsing error - Unsupported ds18x sensor "
330-
"type count found in JSON!");
331-
return false;
332345
}
333346

334347
// Configure the signal message for the ds18x20 payload

0 commit comments

Comments
 (0)