diff --git a/AfterburnerCRC.exe b/AfterburnerCRC.exe deleted file mode 100644 index efcdfcb..0000000 Binary files a/AfterburnerCRC.exe and /dev/null differ diff --git a/Arduino/Afterburner/Afterburner.ino b/Arduino/Afterburner/Afterburner.ino index 2e5318c..7e06a01 100644 --- a/Arduino/Afterburner/Afterburner.ino +++ b/Arduino/Afterburner/Afterburner.ino @@ -330,6 +330,7 @@ void setup() { NVstore.load(); initMQTTJSONmoderator(); // prevents JSON for MQTT unless requested + initIPJSONmoderator(); // prevents JSON for IP unless requested initTimerJSONmoderator(); // prevents JSON for timers unless requested @@ -742,7 +743,8 @@ void loop() ScreenManager.reqUpdate(); } - updateFilteredData(); + if(bHasHtrData) + updateFilteredData(); updateJSONclients(bReportJSONData); CommState.set(CommStates::Idle); NVstore.doSave(); // now is a good time to store to the NV storage, well away from any blue wire activity diff --git a/CRCgen/AfterBurnerCRC.cpp b/CRCgen/AfterBurnerCRC.cpp index cd215e4..cfaaa71 100644 Binary files a/CRCgen/AfterBurnerCRC.cpp and b/CRCgen/AfterBurnerCRC.cpp differ diff --git a/CRCgen/Readme.txt b/CRCgen/Readme.txt new file mode 100644 index 0000000..bcc099d --- /dev/null +++ b/CRCgen/Readme.txt @@ -0,0 +1,11 @@ +AfterburnerCRC.cpp is used to append a CRC-16 value to the +compiled binary file. + +This CRC is used to confirm the binary image uploaded to the +Afterburner was genuinely intended for the Afterburner. + +Naively attempting to upload the direct compiled output binary +will result in rejection of the upload attempt. + +You will need to compile Afterburner.cpp and copy the resultant +executable to the repository root (adjacent to plaformio.ini) \ No newline at end of file diff --git a/src/Afterburner/Afterburner.cpp b/src/Afterburner/Afterburner.cpp index 2e5318c..7e06a01 100644 --- a/src/Afterburner/Afterburner.cpp +++ b/src/Afterburner/Afterburner.cpp @@ -330,6 +330,7 @@ void setup() { NVstore.load(); initMQTTJSONmoderator(); // prevents JSON for MQTT unless requested + initIPJSONmoderator(); // prevents JSON for IP unless requested initTimerJSONmoderator(); // prevents JSON for timers unless requested @@ -742,7 +743,8 @@ void loop() ScreenManager.reqUpdate(); } - updateFilteredData(); + if(bHasHtrData) + updateFilteredData(); updateJSONclients(bReportJSONData); CommState.set(CommStates::Idle); NVstore.doSave(); // now is a good time to store to the NV storage, well away from any blue wire activity diff --git a/src/Afterburner/src/Utility/BTC_JSON.cpp b/src/Afterburner/src/Utility/BTC_JSON.cpp index 9387267..570b18a 100644 --- a/src/Afterburner/src/Utility/BTC_JSON.cpp +++ b/src/Afterburner/src/Utility/BTC_JSON.cpp @@ -27,16 +27,17 @@ #include "../RTC/TimerManager.h" #include "../Bluetooth/BluetoothAbstract.h" #include "../WiFi/BTCWebServer.h" +#include "../WiFi/BTCWifi.h" #include "../cfg/BTCConfig.h" #include "macros.h" #include "../Protocol/Protocol.h" - char defaultJSONstr[64]; CModerator JSONmoderator; CTimerModerator TimerModerator; int timerConflict = 0; CModerator MQTTmoderator; +CModerator IPmoderator; CModerator GPIOmoderator; void validateTimer(int ID); @@ -179,6 +180,9 @@ void interpretJsonCommand(char* pLine) else if(strcmp("FanSensor", it->key) == 0) { setFanSensor(it->value.as()); } + else if(strcmp("IQuery", it->key) == 0) { + IPmoderator.reset(); // force IP params to be sent + } // MQTT parameters else if(strcmp("MQuery", it->key) == 0) { MQTTmoderator.reset(); // force MQTT params to be sent @@ -395,6 +399,26 @@ bool makeJSONStringMQTT(CModerator& moderator, char* opStr, int len) return bSend; } +bool makeJSONStringIP(CModerator& moderator, char* opStr, int len) +{ + StaticJsonBuffer<800> jsonBuffer; // create a JSON buffer on the stack + JsonObject& root = jsonBuffer.createObject(); // create object to add JSON commands to + + bool bSend = false; // reset should send flag + + bSend |= moderator.addJson("IP_AP", getWifiAPAddrStr(), root); + bSend |= moderator.addJson("IP_APMAC", getWifiAPMACStr(), root); + bSend |= moderator.addJson("IP_STA", getWifiSTAAddrStr(), root); + bSend |= moderator.addJson("IP_STAMAC", getWifiSTAMACStr(), root); + bSend |= moderator.addJson("IP_STASSID", getSSID().c_str(), root); + bSend |= moderator.addJson("IP_OTA", NVstore.getUserSettings().enableOTA, root); + + if(bSend) { + root.printTo(opStr, len); + } + + return bSend; +} void updateJSONclients(bool report) { @@ -477,6 +501,19 @@ void updateJSONclients(bool report) } } + // report MQTT params + { + if(makeJSONStringIP(IPmoderator, jsonStr, sizeof(jsonStr))) { + if (report) { + DebugPort.printf("JSON send: %s\r\n", jsonStr); + } + sendWebSocketString( jsonStr ); + std::string expand = jsonStr; + Expand(expand); + getBluetoothClient().send( expand.c_str() ); + } + } + { if(makeJSONStringGPIO(GPIOmoderator, jsonStr, sizeof(jsonStr))) { if (report) { @@ -501,6 +538,7 @@ void resetJSONmoderator() initTimerJSONmoderator(); #endif initMQTTJSONmoderator(); + initIPJSONmoderator(); GPIOmoderator.reset(); } @@ -510,6 +548,12 @@ void initMQTTJSONmoderator() makeJSONStringMQTT(MQTTmoderator, jsonStr, sizeof(jsonStr)); } +void initIPJSONmoderator() +{ + char jsonStr[800]; + makeJSONStringIP(IPmoderator, jsonStr, sizeof(jsonStr)); +} + void initTimerJSONmoderator() { char jsonStr[800]; diff --git a/src/Afterburner/src/Utility/BTC_JSON.h b/src/Afterburner/src/Utility/BTC_JSON.h index fcd5cbc..b42efa9 100644 --- a/src/Afterburner/src/Utility/BTC_JSON.h +++ b/src/Afterburner/src/Utility/BTC_JSON.h @@ -33,7 +33,9 @@ bool makeJSONTimerString(int channel, char* opStr, int len); bool makeJSONStringGPIO( CModerator& moderator, char* opStr, int len); void updateJSONclients(bool report); bool makeJSONStringMQTT(CModerator& moderator, char* opStr, int len); +bool makeJSONStringIP(CModerator& moderator, char* opStr, int len); void initMQTTJSONmoderator(); +void initIPJSONmoderator(); void initTimerJSONmoderator(); template diff --git a/src/Afterburner/src/WiFi/BTCWifi.cpp b/src/Afterburner/src/WiFi/BTCWifi.cpp index 3184c4e..80ad9d0 100644 --- a/src/Afterburner/src/WiFi/BTCWifi.cpp +++ b/src/Afterburner/src/WiFi/BTCWifi.cpp @@ -298,6 +298,13 @@ const char* getWifiSTAMACStr() return MACstr[0]; } +String getSSID() +{ + wifi_config_t conf; + esp_wifi_get_config(WIFI_IF_STA, &conf); + return String(reinterpret_cast(conf.sta.ssid)); +} + bool isWifiConnected() { return WiFi.status() == WL_CONNECTED; diff --git a/src/Afterburner/src/WiFi/BTCWifi.h b/src/Afterburner/src/WiFi/BTCWifi.h index 9c1162c..493f04b 100644 --- a/src/Afterburner/src/WiFi/BTCWifi.h +++ b/src/Afterburner/src/WiFi/BTCWifi.h @@ -30,6 +30,7 @@ const char* getWifiAPAddrStr(); const char* getWifiSTAAddrStr(); const char* getWifiAPMACStr(); const char* getWifiSTAMACStr(); +String getSSID(); bool isWifiConnected(); bool isWifiAP();