Added JSON IP query parameters

This commit is contained in:
Ray Jones 2019-07-11 22:03:27 +10:00
parent de1eb48f78
commit 1f28bb7d5d
9 changed files with 72 additions and 3 deletions

Binary file not shown.

View File

@ -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

Binary file not shown.

11
CRCgen/Readme.txt Normal file
View File

@ -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)

View File

@ -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

View File

@ -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<uint8_t>());
}
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];

View File

@ -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<class T>

View File

@ -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<const char*>(conf.sta.ssid));
}
bool isWifiConnected()
{
return WiFi.status() == WL_CONNECTED;

View File

@ -30,6 +30,7 @@ const char* getWifiAPAddrStr();
const char* getWifiSTAAddrStr();
const char* getWifiAPMACStr();
const char* getWifiSTAMACStr();
String getSSID();
bool isWifiConnected();
bool isWifiAP();