mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-24 11:46:34 +00:00
Add jsonl command
This commit is contained in:
parent
b82f8d6df9
commit
b54a85fd94
38
include/StringStream.h
Normal file
38
include/StringStream.h
Normal file
@ -0,0 +1,38 @@
|
||||
#ifndef _STRING_STREAM_H_
|
||||
#define _STRING_STREAM_H_
|
||||
|
||||
#include <Stream.h>
|
||||
|
||||
class StringStream : public Stream {
|
||||
public:
|
||||
StringStream(String & s) : string(s), position(0)
|
||||
{}
|
||||
|
||||
// Stream methods
|
||||
virtual int available()
|
||||
{
|
||||
return string.length() - position;
|
||||
}
|
||||
virtual int read()
|
||||
{
|
||||
return position < string.length() ? string[position++] : -1;
|
||||
}
|
||||
virtual int peek()
|
||||
{
|
||||
return position < string.length() ? string[position] : -1;
|
||||
}
|
||||
virtual void flush(){};
|
||||
// Print methods
|
||||
virtual size_t write(uint8_t c)
|
||||
{
|
||||
string += (char)c;
|
||||
return 1;
|
||||
};
|
||||
|
||||
private:
|
||||
String & string;
|
||||
unsigned int length;
|
||||
unsigned int position;
|
||||
};
|
||||
|
||||
#endif // _STRING_STREAM_H_
|
@ -82,6 +82,7 @@ void haspBackground(uint16_t pageid, uint16_t imageid);
|
||||
void haspProcessAttribute(uint8_t pageid, uint8_t objid, String strAttr, String strPayload);
|
||||
void haspSendCmd(String nextionCmd);
|
||||
void haspParseJson(String & strPayload);
|
||||
void haspNewObject(const JsonObject & settings);
|
||||
|
||||
void haspReconnect(void);
|
||||
void haspDisconnect(void);
|
||||
|
@ -1,3 +1,6 @@
|
||||
#include "StringStream.h"
|
||||
#include "ArduinoJson.h"
|
||||
|
||||
#include "hasp_dispatch.h"
|
||||
#include "hasp_config.h"
|
||||
#include "hasp_debug.h"
|
||||
@ -124,6 +127,24 @@ void dispatchJson(char * payload)
|
||||
}
|
||||
}
|
||||
|
||||
void dispatchJsonl(char * strPayload)
|
||||
{
|
||||
Serial.println("JSONL\n");
|
||||
DynamicJsonDocument config(254);
|
||||
|
||||
String output((char *)0);
|
||||
output.reserve(1500);
|
||||
|
||||
StringStream stream((String &)output);
|
||||
stream.print(strPayload);
|
||||
|
||||
while(deserializeJson(config, stream) == DeserializationError::Ok) {
|
||||
serializeJson(config, Serial);
|
||||
Serial.println();
|
||||
haspNewObject(config.as<JsonObject>());
|
||||
}
|
||||
}
|
||||
|
||||
void IRAM_ATTR dispatchIdle(const __FlashStringHelper * state)
|
||||
{
|
||||
mqttSendState(String(F("idle")).c_str(), String(state).c_str());
|
||||
|
@ -9,6 +9,7 @@ void dispatchLoop(void);
|
||||
void dispatchAttribute(String & strTopic, const char * strPayload);
|
||||
void dispatchCommand(String cmnd);
|
||||
void dispatchJson(char * strPayload);
|
||||
void dispatchJsonl(char * strPayload);
|
||||
|
||||
void dispatchPage(String strPageid);
|
||||
void dispatchDim(String strDimLevel);
|
||||
|
@ -241,8 +241,12 @@ void mqttCallback(char * topic, byte * payload, unsigned int length)
|
||||
if(strTopic == F("json")) { // '[...]/device/command/json' -m '["dim=5", "page 1"]' =
|
||||
// nextionSendCmd("dim=50"), nextionSendCmd("page 1")
|
||||
dispatchJson((char *)payload); // Send to nextionParseJson()
|
||||
} else { // '[...]/device/command/p[1].b[4].txt' -m '"Lights On"' ==
|
||||
// nextionSetAttr("p[1].b[4].txt", "\"Lights On\"")
|
||||
} else if(strTopic == F("jsonl")) {
|
||||
dispatchJsonl((char *)payload);
|
||||
} else if(strTopic == F("setupap")) {
|
||||
haspDisplayAP("HASP-ABC123", "haspadmin");
|
||||
} else { // '[...]/device/command/p[1].b[4].txt' -m '"Lights On"' ==
|
||||
// nextionSetAttr("p[1].b[4].txt", "\"Lights On\"")
|
||||
dispatchAttribute(strTopic, (char *)payload);
|
||||
}
|
||||
return;
|
||||
|
Loading…
x
Reference in New Issue
Block a user