diff --git a/.github/workflows/workflow.yaml b/.github/workflows/workflow.yaml index bff6add79d..8dafd1df5f 100644 --- a/.github/workflows/workflow.yaml +++ b/.github/workflows/workflow.yaml @@ -58,7 +58,7 @@ jobs: build2: name: Build Simulator needs: refs - runs-on: windows-latest + runs-on: windows-2022 steps: - name: Checkout repository @@ -620,4 +620,4 @@ jobs: echo ${{ steps.semantic.outputs.new_release_version }} echo ${{ steps.semantic.outputs.new_release_major_version }} echo ${{ steps.semantic.outputs.new_release_minor_version }} - echo ${{ steps.semantic.outputs.new_release_patch_version }} \ No newline at end of file + echo ${{ steps.semantic.outputs.new_release_patch_version }} diff --git a/src/driver/drv_ds1820_full.c b/src/driver/drv_ds1820_full.c index 1c79dc646b..e1689fbf41 100644 --- a/src/driver/drv_ds1820_full.c +++ b/src/driver/drv_ds1820_full.c @@ -736,6 +736,41 @@ void DS1820_full_driver_Init() }; + +/* + printer(request, "\"DS1820\":"); + // following check will clear NaN values + printer(request, "{"); + printer(request, "\"Temperature\": %.1f,", chan_val1); + // close ENERGY block + printer(request, "},"); + +*/ + +static char *jsonSensor_reststr = NULL; +char *DS1820_full_jsonSensors(){ + if (ds18_count <= 0 ) return NULL; + if (jsonSensor_reststr!=NULL) free(jsonSensor_reststr); + // {"DS1820_":{"Temperature": }, + // {"DS1820_":{"Temperature": }, + // 123456789 123456789012345678 1234567890 + // length of str: 10 + DS18B20namel + 18 + 10 --> 40 + DS18B20namel + + int size = (40 + DS18B20namel) * ds18_count; + char *str = (char *)malloc(size * sizeof(char)); + if (str == NULL) { + return NULL; // string allocation failed + } + str[0] = 0; + for (int i=0; i < ds18_count; i++) { + char tmp[50 + DS18B20namel]; + sprintf(tmp, "\"DS1820_%s\":{\"Temperature\": %.1f},",ds18b20devices.name[i],ds18b20devices.lasttemp[i]); + strncat(str, tmp, size - strlen(str) - 1); // Concatenate to the main string + } + jsonSensor_reststr = str; + return jsonSensor_reststr; +} + void DS1820_full_AppendInformationToHTTPIndexPage(http_request_t* request, int bPreState) { if (bPreState){ diff --git a/src/driver/drv_ds1820_full.h b/src/driver/drv_ds1820_full.h index cdeffce715..a7dc285024 100644 --- a/src/driver/drv_ds1820_full.h +++ b/src/driver/drv_ds1820_full.h @@ -24,4 +24,4 @@ float ds18b20_getTempC(const uint8_t *deviceAddress); bool isConversionComplete(); void reset_search(); bool search(uint8_t *newAddr, bool search_mode, int Pin); - +char *DS1820_full_jsonSensors(); diff --git a/src/driver/drv_main.c b/src/driver/drv_main.c index 3ca9c61ade..0fd71f26bc 100644 --- a/src/driver/drv_main.c +++ b/src/driver/drv_main.c @@ -852,7 +852,7 @@ bool DRV_IsMeasuringBattery() { bool DRV_IsSensor() { #ifndef OBK_DISABLE_ALL_DRIVERS - return DRV_IsRunning("SHT3X") || DRV_IsRunning("CHT83XX") || DRV_IsRunning("SGP") || DRV_IsRunning("AHT2X"); + return DRV_IsRunning("SHT3X") || DRV_IsRunning("CHT83XX") || DRV_IsRunning("SGP") || DRV_IsRunning("AHT2X") || DRV_IsRunning("DS1820") || DRV_IsRunning("DS1820_full"); #else return false; #endif diff --git a/src/httpserver/json_interface.c b/src/httpserver/json_interface.c index ecec403daa..304a9f6ddd 100644 --- a/src/httpserver/json_interface.c +++ b/src/httpserver/json_interface.c @@ -20,6 +20,9 @@ #include "../driver/drv_ntp.h" #include "../driver/drv_local.h" #include "../driver/drv_bl_shared.h" +#include "../driver/drv_ds1820_simple.h" +#include "../driver/drv_ds1820_full.h" + #if ENABLE_TASMOTA_JSON @@ -278,6 +281,36 @@ static int http_tasmota_json_SENSOR(void* request, jsonCb_t printer) { // close ENERGY block printer(request, "},"); } +#if (ENABLE_DRIVER_DS1820) + if (DRV_IsRunning("DS1820")) { //DS1820_simple.c with one sensor + g_pin_1 = PIN_FindPinIndexForRole(IOR_DS1820_IO, g_pin_1); + channel_1 = g_cfg.pins.channels[g_pin_1]; + chan_val1 = CHANNEL_GetFloat(channel_1) / 100.0f; + + // writer header + printer(request, "\"DS1820\":"); + // following check will clear NaN values + printer(request, "{"); + printer(request, "\"Temperature\": %.1f", chan_val1); + // close ENERGY block + printer(request, "},"); + } +#endif +#if (ENABLE_DRIVER_DS1820_FULL) + if (DRV_IsRunning("DS1820_full")) { //DS1820_full.c with possibly multiple sensors + char *str = DS1820_full_jsonSensors(); + int toprint = strlen(str); + while (*str && toprint > 250) { // string can be long, longer than request, this would break output if not split + char t = str[250]; + str[250]=0; + printer(request, str); + str[250]=t; + str+=250; + toprint -= 250; + } + printer(request, str); + } +#endif if (DRV_IsRunning("CHT83XX")) { g_pin_1 = PIN_FindPinIndexForRole(IOR_CHT83XX_DAT, g_pin_1); channel_1 = g_cfg.pins.channels[g_pin_1]; @@ -295,6 +328,7 @@ static int http_tasmota_json_SENSOR(void* request, jsonCb_t printer) { // close ENERGY block printer(request, "},"); } + for (int i = 0; i < PLATFORM_GPIO_MAX; i++) { int role = PIN_GetPinRoleForPinIndex(i); if (role != IOR_DHT11 && role != IOR_DHT12 && role != IOR_DHT21 && role != IOR_DHT22)