[SD] ds18x20 decode thru controller via HandleAdd OK
This commit is contained in:
parent
bf7b7de3fc
commit
f0f574a0ac
3 changed files with 83 additions and 30 deletions
38
src/Wippersnapper_demo_wokwi.ino.cpp
Normal file
38
src/Wippersnapper_demo_wokwi.ino.cpp
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
# 1 "/var/folders/ff/dmzflvf52tq9kzvt6g8jglxw0000gn/T/tmpi83fbtc8"
|
||||
#include <Arduino.h>
|
||||
# 1 "/Users/brentrubell/Documents/Arduino/libraries/Adafruit_Wippersnapper_Arduino/src/Wippersnapper_demo_wokwi.ino"
|
||||
# 14 "/Users/brentrubell/Documents/Arduino/libraries/Adafruit_Wippersnapper_Arduino/src/Wippersnapper_demo_wokwi.ino"
|
||||
#define IO_USERNAME "brubell"
|
||||
#define IO_KEY "YOUR_AIO_KEY"
|
||||
|
||||
#define WIFI_SSID "Wokwi-GUEST"
|
||||
#define WIFI_PASS ""
|
||||
|
||||
#define WS_DEBUG
|
||||
|
||||
#define API_PIN 0
|
||||
|
||||
#include "ws_manager.h"
|
||||
|
||||
|
||||
Wippersnapper_Manager manager;
|
||||
Wippersnapper_WiFiV2 wipper(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, "io.adafruit.com", 8883);
|
||||
void setup();
|
||||
void loop();
|
||||
#line 31 "/Users/brentrubell/Documents/Arduino/libraries/Adafruit_Wippersnapper_Arduino/src/Wippersnapper_demo_wokwi.ino"
|
||||
void setup() {
|
||||
|
||||
manager.checkAPIVersion(API_PIN);
|
||||
manager.provision();
|
||||
|
||||
Serial.begin(115200);
|
||||
|
||||
Serial.println("Adafruit Wippersnapper API Manager Demo");
|
||||
Serial.print("Running Wippersnapper API Version: ");
|
||||
Serial.println(manager.getAPIVersion());
|
||||
manager.connect();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
manager.run();
|
||||
}
|
||||
|
|
@ -102,19 +102,21 @@ bool DS18X20Controller::Handle_Ds18x20Add(pb_istream_t *stream) {
|
|||
is_initialized = false;
|
||||
}
|
||||
|
||||
// Encode and publish a Ds18x20Added message back to the broker
|
||||
unsigned long encode_start_time = millis();
|
||||
if (!_DS18X20_model->EncodeDS18x20Added(
|
||||
_DS18X20_model->GetDS18x20AddMsg()->onewire_pin, is_initialized)) {
|
||||
WS_DEBUG_PRINTLN("ERROR | DS18x20: Unable to encode Ds18x20Added message!");
|
||||
return false;
|
||||
}
|
||||
// If we're not in offline mode, publish a Ds18x20Added message back to the broker
|
||||
if (! WsV2._sdCardV2->mode_offline) {
|
||||
// Encode and publish a Ds18x20Added message back to the broker
|
||||
if (!_DS18X20_model->EncodeDS18x20Added(
|
||||
_DS18X20_model->GetDS18x20AddMsg()->onewire_pin, is_initialized)) {
|
||||
WS_DEBUG_PRINTLN("ERROR | DS18x20: Unable to encode Ds18x20Added message!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!WsV2.PublishSignal(wippersnapper_signal_DeviceToBroker_ds18x20_added_tag,
|
||||
_DS18X20_model->GetDS18x20AddedMsg())) {
|
||||
WS_DEBUG_PRINTLN(
|
||||
"ERROR | DS18x20: Unable to publish Ds18x20Added message!");
|
||||
return false;
|
||||
if (!WsV2.PublishSignal(wippersnapper_signal_DeviceToBroker_ds18x20_added_tag,
|
||||
_DS18X20_model->GetDS18x20AddedMsg())) {
|
||||
WS_DEBUG_PRINTLN(
|
||||
"ERROR | DS18x20: Unable to publish Ds18x20Added message!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -305,30 +305,43 @@ bool ws_sdcard::parseConfigFile() {
|
|||
return false;
|
||||
}
|
||||
|
||||
WS_DEBUG_PRINT("[SD] msg_DS18X20Add.sensor_types_count: ");
|
||||
WS_DEBUG_PRINTLN(msg_DS18X20Add.sensor_types_count);
|
||||
|
||||
// Parse the sensor types into the DS18X20Add message
|
||||
// TODO: This structor needs a refactoring pass! It's too confusing
|
||||
if (msg_DS18X20Add.sensor_types_count == 1) {
|
||||
if (component["sensorType1"] != nullptr) {
|
||||
msg_DS18X20Add.sensor_types[0] = component["sensorType1"];
|
||||
if (msg_DS18X20Add.sensor_types_count == 1 ||
|
||||
msg_DS18X20Add.sensor_types_count == 2) {
|
||||
if (strcmp(component["sensorType1"], "ambient-temp-fahrenheit") == 0) {
|
||||
msg_DS18X20Add.sensor_types[0] =
|
||||
wippersnapper_sensor_SensorType_SENSOR_TYPE_OBJECT_TEMPERATURE_FAHRENHEIT;
|
||||
} else if (strcmp(component["sensorType1"], "ambient-temp") == 0) {
|
||||
msg_DS18X20Add.sensor_types[0] =
|
||||
wippersnapper_sensor_SensorType_SENSOR_TYPE_OBJECT_TEMPERATURE;
|
||||
} else {
|
||||
WS_DEBUG_PRINTLN("[SD] FATAL Parsing error - No sensor type found in "
|
||||
"JSON string!");
|
||||
WS_DEBUG_PRINTLN(
|
||||
"[SD] FATAL Parsing error - Unsupported ds18x sensor "
|
||||
"type found in JSON!");
|
||||
return false;
|
||||
}
|
||||
} else if (msg_DS18X20Add.sensor_types_count == 2) {
|
||||
if (component["sensorType1"] != nullptr &&
|
||||
component["sensorType2"] != nullptr) {
|
||||
msg_DS18X20Add.sensor_types[0] = component["sensorType1"];
|
||||
msg_DS18X20Add.sensor_types[1] = component["sensorType2"];
|
||||
} else {
|
||||
WS_DEBUG_PRINTLN("[SD] FATAL Parsing error - No sensor type found in "
|
||||
"JSON string!");
|
||||
return false;
|
||||
}
|
||||
if (msg_DS18X20Add.sensor_types_count == 2) {
|
||||
WS_DEBUG_PRINTLN("[SD] Parsing sensor type 2...");
|
||||
if (component["sensorType2"] != nullptr) {
|
||||
if (strcmp(component["sensorType2"], "ambient-temp-fahrenheit") ==
|
||||
0) {
|
||||
msg_DS18X20Add.sensor_types[1] =
|
||||
wippersnapper_sensor_SensorType_SENSOR_TYPE_OBJECT_TEMPERATURE_FAHRENHEIT;
|
||||
} else if (strcmp(component["sensorType2"], "ambient-temp") == 0) {
|
||||
msg_DS18X20Add.sensor_types[1] =
|
||||
wippersnapper_sensor_SensorType_SENSOR_TYPE_OBJECT_TEMPERATURE;
|
||||
} else {
|
||||
WS_DEBUG_PRINTLN(
|
||||
"[SD] FATAL Parsing error - Unsupported ds18x sensor "
|
||||
"type found in JSON!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
WS_DEBUG_PRINTLN("[SD] FATAL Parsing error - Unsupported ds18x sensor "
|
||||
"type count found in JSON!");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Configure the signal message for the ds18x20 payload
|
||||
|
|
|
|||
Loading…
Reference in a new issue