From 97ef705a8827a06462bbe8cd42c7d84ca049294d Mon Sep 17 00:00:00 2001 From: proddy Date: Thu, 3 Oct 2019 14:32:46 +0200 Subject: [PATCH] print device ID in hex correctly in web --- src/ems-esp.cpp | 13 ++++++++++--- src/ems.cpp | 14 +++++++------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/ems-esp.cpp b/src/ems-esp.cpp index b18c23153..c46f36b4f 100644 --- a/src/ems-esp.cpp +++ b/src/ems-esp.cpp @@ -1850,9 +1850,16 @@ void WebCallback(JsonObject root) { item["version"] = (it)->version; item["productid"] = (it)->product_id; - char s[10]; - itoa((it)->device_id, s, 16); // convert to hex - item["deviceid"] = s; + char buffer[10]; + // copy of my _hextoa() function from ems.cpp + // to convert device_id into a 0xXX hex value string + char * p = buffer; + byte nib1 = ((it)->device_id >> 4) & 0x0F; + byte nib2 = ((it)->device_id >> 0) & 0x0F; + *p++ = nib1 < 0xA ? '0' + nib1 : 'A' + nib1 - 0xA; + *p++ = nib2 < 0xA ? '0' + nib2 : 'A' + nib2 - 0xA; + *p = '\0'; // null terminate just in case + item["deviceid"] = buffer; } // send over Thermostat data diff --git a/src/ems.cpp b/src/ems.cpp index 25e3a17f1..ddcfd3c94 100644 --- a/src/ems.cpp +++ b/src/ems.cpp @@ -1966,7 +1966,7 @@ void _process_UBADevices(_EMS_RxTelegram * EMS_RxTelegram) { /** * type 0x02 - get the firmware version and type of an EMS device - * look up known devices via the product id and setup if not already set + * look up known devices via the product id and make it active if not already setup */ void _process_Version(_EMS_RxTelegram * EMS_RxTelegram) { // ignore short messages that we can't interpret @@ -1983,7 +1983,7 @@ void _process_Version(_EMS_RxTelegram * EMS_RxTelegram) { if (EMS_RxTelegram->data[3] != 0x00) { offset = 3; } else { - return; // ignore telegram + return; // ignore whole telegram } } @@ -2049,7 +2049,7 @@ void _process_Version(_EMS_RxTelegram * EMS_RxTelegram) { if (typeFound) { // its a known thermostat, add to list - _addDevice(EMS_MODELTYPE_THERMOSTAT, EMS_RxTelegram->src, product_id, version, i); // type 2 = thermostat + _addDevice(EMS_MODELTYPE_THERMOSTAT, EMS_RxTelegram->src, product_id, version, i); // if we don't have a thermostat set, use this one. it will pick the first one. if (((EMS_Thermostat.device_id == EMS_ID_NONE) || (EMS_Thermostat.model_id == EMS_MODEL_NONE) @@ -2088,7 +2088,7 @@ void _process_Version(_EMS_RxTelegram * EMS_RxTelegram) { if (typeFound) { // its a known SM, add to list - _addDevice(EMS_MODELTYPE_SM, EMS_RxTelegram->src, product_id, version, i); // type 3 = other + _addDevice(EMS_MODELTYPE_SM, EMS_RxTelegram->src, product_id, version, i); // myDebug_P(PSTR("Solar Module support enabled.")); EMS_SolarModule.device_id = SolarModule_Devices[i].device_id; @@ -2112,7 +2112,7 @@ void _process_Version(_EMS_RxTelegram * EMS_RxTelegram) { if (typeFound) { // its a known SM, add to list - _addDevice(EMS_MODELTYPE_HP, EMS_RxTelegram->src, product_id, version, i); // type 3 = other + _addDevice(EMS_MODELTYPE_HP, EMS_RxTelegram->src, product_id, version, i); // myDebug_P(PSTR("Heat Pump support enabled.")); EMS_HeatPump.device_id = SolarModule_Devices[i].device_id; @@ -2133,10 +2133,10 @@ void _process_Version(_EMS_RxTelegram * EMS_RxTelegram) { if (typeFound) { // its a known other device, add to list - _addDevice(EMS_MODELTYPE_OTHER, EMS_RxTelegram->src, product_id, version, i); // type 3 = other + _addDevice(EMS_MODELTYPE_OTHER, EMS_RxTelegram->src, product_id, version, i); } else { // didn't recognize, add to list anyway - _addDevice(EMS_MODELTYPE_UNKNOWN, EMS_RxTelegram->src, product_id, version, 0); // type 4 = unknown + _addDevice(EMS_MODELTYPE_UNKNOWN, EMS_RxTelegram->src, product_id, version, 0); } }