mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
wifi array с обратной совместимостью
This commit is contained in:
@@ -15,7 +15,7 @@ extern bool jsonRead(const String& json, String key, float& value, bool e = true
|
|||||||
extern bool jsonRead(const String& json, String key, String& value, bool e = true);
|
extern bool jsonRead(const String& json, String key, String& value, bool e = true);
|
||||||
extern bool jsonRead(const String& json, String key, bool& value, bool e = true);
|
extern bool jsonRead(const String& json, String key, bool& value, bool e = true);
|
||||||
extern bool jsonRead(const String& json, String key, int& value, bool e = true);
|
extern bool jsonRead(const String& json, String key, int& value, bool e = true);
|
||||||
extern bool jsonReadArray(const String& json, String key, JsonArray& jArray, bool e = true);
|
extern bool jsonReadArray(const String& json, String key, std::vector<String>& jArray, bool e = true);
|
||||||
|
|
||||||
extern String jsonReadStr(const String& json, String name, bool e = true);
|
extern String jsonReadStr(const String& json, String name, bool e = true);
|
||||||
extern int jsonReadInt(const String& json, String name, bool e = true);
|
extern int jsonReadInt(const String& json, String name, bool e = true);
|
||||||
|
|||||||
@@ -2,11 +2,11 @@
|
|||||||
|
|
||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
#include "MqttClient.h"
|
#include "MqttClient.h"
|
||||||
|
#include <vector>
|
||||||
// boolean isNetworkActive();
|
// boolean isNetworkActive();
|
||||||
inline boolean isNetworkActive() {return WiFi.status() == WL_CONNECTED;};
|
inline boolean isNetworkActive() {return WiFi.status() == WL_CONNECTED;};
|
||||||
void routerConnect();
|
void routerConnect();
|
||||||
bool startAPMode();
|
bool startAPMode();
|
||||||
boolean RouterFind(JsonArray jArray);
|
boolean RouterFind(std::vector<String> jArray);
|
||||||
uint8_t RSSIquality();
|
uint8_t RSSIquality();
|
||||||
extern void wifiSignalInit();
|
extern void wifiSignalInit();
|
||||||
|
|||||||
@@ -176,7 +176,7 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload,
|
|||||||
// запуск асинхронного сканирования wifi сетей при нажатии выпадающего
|
// запуск асинхронного сканирования wifi сетей при нажатии выпадающего
|
||||||
// списка
|
// списка
|
||||||
if (headerStr == "/scan|") {
|
if (headerStr == "/scan|") {
|
||||||
JsonArray jArray;
|
std::vector<String> jArray;
|
||||||
jsonReadArray(settingsFlashJson, "routerssid", jArray);
|
jsonReadArray(settingsFlashJson, "routerssid", jArray);
|
||||||
RouterFind(jArray);
|
RouterFind(jArray);
|
||||||
sendStringToWs("ssidli", ssidListHeapJson, num);
|
sendStringToWs("ssidli", ssidListHeapJson, num);
|
||||||
|
|||||||
@@ -2,26 +2,34 @@
|
|||||||
#include "utils/FileUtils.h"
|
#include "utils/FileUtils.h"
|
||||||
|
|
||||||
// new================================================================================
|
// new================================================================================
|
||||||
String jsonReadStrDoc(DynamicJsonDocument& doc, String name) {
|
String jsonReadStrDoc(DynamicJsonDocument &doc, String name)
|
||||||
|
{
|
||||||
return doc[name].as<String>();
|
return doc[name].as<String>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void jsonWriteStrDoc(DynamicJsonDocument& doc, String name, String value) {
|
void jsonWriteStrDoc(DynamicJsonDocument &doc, String name, String value)
|
||||||
|
{
|
||||||
doc[name] = value;
|
doc[name] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// new==============================================================================
|
// new==============================================================================
|
||||||
bool jsonRead(const String& json, String key, long& value, bool e) {
|
bool jsonRead(const String &json, String key, long &value, bool e)
|
||||||
|
{
|
||||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||||
DeserializationError error = deserializeJson(doc, json);
|
DeserializationError error = deserializeJson(doc, json);
|
||||||
if (error) {
|
if (error)
|
||||||
if (e) {
|
{
|
||||||
|
if (e)
|
||||||
|
{
|
||||||
SerialPrint("E", F("jsonRead"), error.f_str());
|
SerialPrint("E", F("jsonRead"), error.f_str());
|
||||||
jsonErrorDetected();
|
jsonErrorDetected();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
} else if (!doc.containsKey(key)) {
|
}
|
||||||
if (e) {
|
else if (!doc.containsKey(key))
|
||||||
|
{
|
||||||
|
if (e)
|
||||||
|
{
|
||||||
SerialPrint("E", F("jsonRead"), key + " missing in " + json);
|
SerialPrint("E", F("jsonRead"), key + " missing in " + json);
|
||||||
jsonErrorDetected();
|
jsonErrorDetected();
|
||||||
}
|
}
|
||||||
@@ -31,17 +39,23 @@ bool jsonRead(const String& json, String key, long& value, bool e) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool jsonRead(const String& json, String key, float& value, bool e) {
|
bool jsonRead(const String &json, String key, float &value, bool e)
|
||||||
|
{
|
||||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||||
DeserializationError error = deserializeJson(doc, json);
|
DeserializationError error = deserializeJson(doc, json);
|
||||||
if (error) {
|
if (error)
|
||||||
if (e) {
|
{
|
||||||
|
if (e)
|
||||||
|
{
|
||||||
SerialPrint("E", F("jsonRead"), error.f_str());
|
SerialPrint("E", F("jsonRead"), error.f_str());
|
||||||
jsonErrorDetected();
|
jsonErrorDetected();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
} else if (!doc.containsKey(key)) {
|
}
|
||||||
if (e) {
|
else if (!doc.containsKey(key))
|
||||||
|
{
|
||||||
|
if (e)
|
||||||
|
{
|
||||||
SerialPrint("E", F("jsonRead"), key + " missing in " + json);
|
SerialPrint("E", F("jsonRead"), key + " missing in " + json);
|
||||||
jsonErrorDetected();
|
jsonErrorDetected();
|
||||||
}
|
}
|
||||||
@@ -51,17 +65,23 @@ bool jsonRead(const String& json, String key, float& value, bool e) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool jsonRead(const String& json, String key, String& value, bool e) {
|
bool jsonRead(const String &json, String key, String &value, bool e)
|
||||||
|
{
|
||||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||||
DeserializationError error = deserializeJson(doc, json);
|
DeserializationError error = deserializeJson(doc, json);
|
||||||
if (error) {
|
if (error)
|
||||||
if (e) {
|
{
|
||||||
|
if (e)
|
||||||
|
{
|
||||||
SerialPrint("E", F("jsonRead"), error.f_str());
|
SerialPrint("E", F("jsonRead"), error.f_str());
|
||||||
jsonErrorDetected();
|
jsonErrorDetected();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
} else if (!doc.containsKey(key)) {
|
}
|
||||||
if (e) {
|
else if (!doc.containsKey(key))
|
||||||
|
{
|
||||||
|
if (e)
|
||||||
|
{
|
||||||
SerialPrint("E", F("jsonRead"), key + " missing in " + json);
|
SerialPrint("E", F("jsonRead"), key + " missing in " + json);
|
||||||
jsonErrorDetected();
|
jsonErrorDetected();
|
||||||
}
|
}
|
||||||
@@ -71,24 +91,31 @@ bool jsonRead(const String& json, String key, String& value, bool e) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool jsonRead(const String& json, String key, bool& value, bool e) {
|
bool jsonRead(const String &json, String key, bool &value, bool e)
|
||||||
|
{
|
||||||
int lvalue = value;
|
int lvalue = value;
|
||||||
bool ret = jsonRead(json, key, lvalue, e);
|
bool ret = jsonRead(json, key, lvalue, e);
|
||||||
value = lvalue;
|
value = lvalue;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool jsonRead(const String& json, String key, int& value, bool e) {
|
bool jsonRead(const String &json, String key, int &value, bool e)
|
||||||
|
{
|
||||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||||
DeserializationError error = deserializeJson(doc, json);
|
DeserializationError error = deserializeJson(doc, json);
|
||||||
if (error) {
|
if (error)
|
||||||
if (e) {
|
{
|
||||||
|
if (e)
|
||||||
|
{
|
||||||
SerialPrint("E", F("jsonRead"), error.f_str());
|
SerialPrint("E", F("jsonRead"), error.f_str());
|
||||||
jsonErrorDetected();
|
jsonErrorDetected();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
} else if (!doc.containsKey(key)) {
|
}
|
||||||
if (e) {
|
else if (!doc.containsKey(key))
|
||||||
|
{
|
||||||
|
if (e)
|
||||||
|
{
|
||||||
SerialPrint("E", F("jsonRead"), key + " missing in " + json);
|
SerialPrint("E", F("jsonRead"), key + " missing in " + json);
|
||||||
jsonErrorDetected();
|
jsonErrorDetected();
|
||||||
}
|
}
|
||||||
@@ -98,33 +125,59 @@ bool jsonRead(const String& json, String key, int& value, bool e) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool jsonReadArray(const String& json, String key, JsonArray& jArray, bool e) {
|
bool jsonReadArray(const String &json, String key, std::vector<String> &jArray, bool e)
|
||||||
|
{
|
||||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||||
DeserializationError error = deserializeJson(doc, json);
|
DeserializationError error = deserializeJson(doc, json);
|
||||||
if (error) {
|
if (error)
|
||||||
if (e) {
|
{
|
||||||
|
if (e)
|
||||||
|
{
|
||||||
SerialPrint("E", F("jsonReadArray"), error.f_str());
|
SerialPrint("E", F("jsonReadArray"), error.f_str());
|
||||||
jsonErrorDetected();
|
jsonErrorDetected();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
} else if (!doc.containsKey(key)) {
|
}
|
||||||
if (e) {
|
else if (!doc.containsKey(key))
|
||||||
|
{
|
||||||
|
if (e)
|
||||||
|
{
|
||||||
SerialPrint("E", F("jsonReadArray"), key + " missing in " + json);
|
SerialPrint("E", F("jsonReadArray"), key + " missing in " + json);
|
||||||
jsonErrorDetected();
|
jsonErrorDetected();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
jArray = doc[key];
|
// SerialPrint("E", F("jsonReadArray"), key + " doc " + doc[key].as<String>());
|
||||||
|
if (doc[key].is<JsonArray>())
|
||||||
|
{
|
||||||
|
for (int8_t i = 0; i < doc[key].size(); i++)
|
||||||
|
jArray.push_back(doc[key][i].as<String>());
|
||||||
|
// SerialPrint("E", F("jsonReadArray"), "isArray"+key + " doc " + doc[key].as<String>());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
jArray.push_back(doc[key].as<String>());
|
||||||
|
// DynamicJsonDocument docArr(JSON_BUFFER_SIZE/5);
|
||||||
|
// jArray = doc[key].as<JsonArray>();
|
||||||
|
// String tmp = doc[key].as<String>();
|
||||||
|
// jArray.add("dsdsd");
|
||||||
|
// SerialPrint("E", F("jsonReadArray"), "notArray"+key + " doc " + doc[key].as<String>());
|
||||||
|
// SerialPrint("E", F("jsonReadArray"), "count: " + String(jArray.size()) +" key: " + key + " arr " + jArray[0]);
|
||||||
|
}
|
||||||
|
// SerialPrint("E", F("jsonReadArray"), "count: " + String(jArray.size()) +" key: " + key + " doc " + jArray[0].as<String>());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// new==============================================================================
|
// new==============================================================================
|
||||||
bool jsonWriteStr_(String& json, const String& key, const String& value, bool e) {
|
bool jsonWriteStr_(String &json, const String &key, const String &value, bool e)
|
||||||
|
{
|
||||||
bool ret = true;
|
bool ret = true;
|
||||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||||
DeserializationError error = deserializeJson(doc, json);
|
DeserializationError error = deserializeJson(doc, json);
|
||||||
if (error) {
|
if (error)
|
||||||
if (e) {
|
{
|
||||||
|
if (e)
|
||||||
|
{
|
||||||
SerialPrint("E", F("jsonWrite"), error.f_str());
|
SerialPrint("E", F("jsonWrite"), error.f_str());
|
||||||
jsonErrorDetected();
|
jsonErrorDetected();
|
||||||
}
|
}
|
||||||
@@ -136,12 +189,15 @@ bool jsonWriteStr_(String& json, const String& key, const String& value, bool e)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool jsonWriteBool_(String& json, const String& key, bool value, bool e) {
|
bool jsonWriteBool_(String &json, const String &key, bool value, bool e)
|
||||||
|
{
|
||||||
bool ret = true;
|
bool ret = true;
|
||||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||||
DeserializationError error = deserializeJson(doc, json);
|
DeserializationError error = deserializeJson(doc, json);
|
||||||
if (error) {
|
if (error)
|
||||||
if (e) {
|
{
|
||||||
|
if (e)
|
||||||
|
{
|
||||||
SerialPrint("E", F("jsonWrite"), error.f_str());
|
SerialPrint("E", F("jsonWrite"), error.f_str());
|
||||||
jsonErrorDetected();
|
jsonErrorDetected();
|
||||||
}
|
}
|
||||||
@@ -153,12 +209,15 @@ bool jsonWriteBool_(String& json, const String& key, bool value, bool e) {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool jsonWriteInt_(String& json, const String& key, int value, bool e) {
|
bool jsonWriteInt_(String &json, const String &key, int value, bool e)
|
||||||
|
{
|
||||||
bool ret = true;
|
bool ret = true;
|
||||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||||
DeserializationError error = deserializeJson(doc, json);
|
DeserializationError error = deserializeJson(doc, json);
|
||||||
if (error) {
|
if (error)
|
||||||
if (e) {
|
{
|
||||||
|
if (e)
|
||||||
|
{
|
||||||
SerialPrint("E", F("jsonWrite"), error.f_str());
|
SerialPrint("E", F("jsonWrite"), error.f_str());
|
||||||
jsonErrorDetected();
|
jsonErrorDetected();
|
||||||
}
|
}
|
||||||
@@ -170,12 +229,15 @@ bool jsonWriteInt_(String& json, const String& key, int value, bool e) {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool jsonWriteFloat_(String& json, const String &key, float value, bool e) {
|
bool jsonWriteFloat_(String &json, const String &key, float value, bool e)
|
||||||
|
{
|
||||||
bool ret = true;
|
bool ret = true;
|
||||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||||
DeserializationError error = deserializeJson(doc, json);
|
DeserializationError error = deserializeJson(doc, json);
|
||||||
if (error) {
|
if (error)
|
||||||
if (e) {
|
{
|
||||||
|
if (e)
|
||||||
|
{
|
||||||
SerialPrint("E", F("jsonWrite"), error.f_str());
|
SerialPrint("E", F("jsonWrite"), error.f_str());
|
||||||
jsonErrorDetected();
|
jsonErrorDetected();
|
||||||
}
|
}
|
||||||
@@ -187,24 +249,29 @@ bool jsonWriteFloat_(String& json, const String &key, float value, bool e) {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void writeUint8tValueToJsonString(uint8_t* payload, size_t length, size_t headerLenth, String& json) {
|
void writeUint8tValueToJsonString(uint8_t *payload, size_t length, size_t headerLenth, String &json)
|
||||||
|
{
|
||||||
String payloadStr;
|
String payloadStr;
|
||||||
payloadStr.reserve(length + 1);
|
payloadStr.reserve(length + 1);
|
||||||
for (size_t i = headerLenth; i < length; i++) {
|
for (size_t i = headerLenth; i < length; i++)
|
||||||
|
{
|
||||||
payloadStr += (char)payload[i];
|
payloadStr += (char)payload[i];
|
||||||
}
|
}
|
||||||
jsonMergeObjects(json, payloadStr);
|
jsonMergeObjects(json, payloadStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool jsonMergeObjects(String& json1, String& json2, bool e) {
|
bool jsonMergeObjects(String &json1, String &json2, bool e)
|
||||||
|
{
|
||||||
bool ret = true;
|
bool ret = true;
|
||||||
DynamicJsonDocument doc1(JSON_BUFFER_SIZE);
|
DynamicJsonDocument doc1(JSON_BUFFER_SIZE);
|
||||||
DeserializationError error1 = deserializeJson(doc1, json1);
|
DeserializationError error1 = deserializeJson(doc1, json1);
|
||||||
DynamicJsonDocument doc2(JSON_BUFFER_SIZE);
|
DynamicJsonDocument doc2(JSON_BUFFER_SIZE);
|
||||||
DeserializationError error2 = deserializeJson(doc2, json2);
|
DeserializationError error2 = deserializeJson(doc2, json2);
|
||||||
jsonMergeDocs(doc1.as<JsonObject>(), doc2.as<JsonObject>());
|
jsonMergeDocs(doc1.as<JsonObject>(), doc2.as<JsonObject>());
|
||||||
if (error1 || error2) {
|
if (error1 || error2)
|
||||||
if (e) {
|
{
|
||||||
|
if (e)
|
||||||
|
{
|
||||||
SerialPrint("E", F("json"), "jsonMergeObjects error");
|
SerialPrint("E", F("json"), "jsonMergeObjects error");
|
||||||
jsonErrorDetected();
|
jsonErrorDetected();
|
||||||
}
|
}
|
||||||
@@ -215,18 +282,23 @@ bool jsonMergeObjects(String& json1, String& json2, bool e) {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void jsonMergeDocs(JsonObject dest, JsonObjectConst src) {
|
void jsonMergeDocs(JsonObject dest, JsonObjectConst src)
|
||||||
for (auto kvp : src) {
|
{
|
||||||
|
for (auto kvp : src)
|
||||||
|
{
|
||||||
dest[kvp.key()] = kvp.value();
|
dest[kvp.key()] = kvp.value();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// depricated======================================================================
|
// depricated======================================================================
|
||||||
String jsonReadStr(const String& json, String name, bool e) {
|
String jsonReadStr(const String &json, String name, bool e)
|
||||||
|
{
|
||||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||||
DeserializationError error = deserializeJson(doc, json);
|
DeserializationError error = deserializeJson(doc, json);
|
||||||
if (error) {
|
if (error)
|
||||||
if (e) {
|
{
|
||||||
|
if (e)
|
||||||
|
{
|
||||||
SerialPrint("E", F("jsonRead"), error.f_str());
|
SerialPrint("E", F("jsonRead"), error.f_str());
|
||||||
jsonErrorDetected();
|
jsonErrorDetected();
|
||||||
}
|
}
|
||||||
@@ -234,11 +306,14 @@ String jsonReadStr(const String& json, String name, bool e) {
|
|||||||
return doc[name].as<String>();
|
return doc[name].as<String>();
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean jsonReadBool(const String& json, String name, bool e) {
|
boolean jsonReadBool(const String &json, String name, bool e)
|
||||||
|
{
|
||||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||||
DeserializationError error = deserializeJson(doc, json);
|
DeserializationError error = deserializeJson(doc, json);
|
||||||
if (error) {
|
if (error)
|
||||||
if (e) {
|
{
|
||||||
|
if (e)
|
||||||
|
{
|
||||||
SerialPrint("E", F("jsonRead"), error.f_str());
|
SerialPrint("E", F("jsonRead"), error.f_str());
|
||||||
jsonErrorDetected();
|
jsonErrorDetected();
|
||||||
}
|
}
|
||||||
@@ -246,11 +321,14 @@ boolean jsonReadBool(const String& json, String name, bool e) {
|
|||||||
return doc[name].as<bool>();
|
return doc[name].as<bool>();
|
||||||
}
|
}
|
||||||
|
|
||||||
int jsonReadInt(const String& json, String name, bool e) {
|
int jsonReadInt(const String &json, String name, bool e)
|
||||||
|
{
|
||||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||||
DeserializationError error = deserializeJson(doc, json);
|
DeserializationError error = deserializeJson(doc, json);
|
||||||
if (error) {
|
if (error)
|
||||||
if (e) {
|
{
|
||||||
|
if (e)
|
||||||
|
{
|
||||||
SerialPrint("E", F("jsonRead"), error.f_str());
|
SerialPrint("E", F("jsonRead"), error.f_str());
|
||||||
jsonErrorDetected();
|
jsonErrorDetected();
|
||||||
}
|
}
|
||||||
@@ -258,11 +336,14 @@ int jsonReadInt(const String& json, String name, bool e) {
|
|||||||
return doc[name].as<int>();
|
return doc[name].as<int>();
|
||||||
}
|
}
|
||||||
|
|
||||||
long int jsonReadLInt(const String& json, String name, bool e) {
|
long int jsonReadLInt(const String &json, String name, bool e)
|
||||||
|
{
|
||||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||||
DeserializationError error = deserializeJson(doc, json);
|
DeserializationError error = deserializeJson(doc, json);
|
||||||
if (error) {
|
if (error)
|
||||||
if (e) {
|
{
|
||||||
|
if (e)
|
||||||
|
{
|
||||||
SerialPrint("E", F("jsonRead"), error.f_str());
|
SerialPrint("E", F("jsonRead"), error.f_str());
|
||||||
jsonErrorDetected();
|
jsonErrorDetected();
|
||||||
}
|
}
|
||||||
@@ -271,11 +352,14 @@ long int jsonReadLInt(const String& json, String name, bool e) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// depricated========================================================================
|
// depricated========================================================================
|
||||||
String jsonWriteStr(String& json, String name, String value, bool e) {
|
String jsonWriteStr(String &json, String name, String value, bool e)
|
||||||
|
{
|
||||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||||
DeserializationError error = deserializeJson(doc, json);
|
DeserializationError error = deserializeJson(doc, json);
|
||||||
if (error) {
|
if (error)
|
||||||
if (e) {
|
{
|
||||||
|
if (e)
|
||||||
|
{
|
||||||
SerialPrint("E", F("jsonWrite"), error.f_str());
|
SerialPrint("E", F("jsonWrite"), error.f_str());
|
||||||
jsonErrorDetected();
|
jsonErrorDetected();
|
||||||
}
|
}
|
||||||
@@ -286,11 +370,14 @@ String jsonWriteStr(String& json, String name, String value, bool e) {
|
|||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
String jsonWriteBool(String& json, String name, boolean value, bool e) {
|
String jsonWriteBool(String &json, String name, boolean value, bool e)
|
||||||
|
{
|
||||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||||
DeserializationError error = deserializeJson(doc, json);
|
DeserializationError error = deserializeJson(doc, json);
|
||||||
if (error) {
|
if (error)
|
||||||
if (e) {
|
{
|
||||||
|
if (e)
|
||||||
|
{
|
||||||
SerialPrint("E", F("jsonWrite"), error.f_str());
|
SerialPrint("E", F("jsonWrite"), error.f_str());
|
||||||
jsonErrorDetected();
|
jsonErrorDetected();
|
||||||
}
|
}
|
||||||
@@ -301,11 +388,14 @@ String jsonWriteBool(String& json, String name, boolean value, bool e) {
|
|||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
String jsonWriteInt(String& json, String name, int value, bool e) {
|
String jsonWriteInt(String &json, String name, int value, bool e)
|
||||||
|
{
|
||||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||||
DeserializationError error = deserializeJson(doc, json);
|
DeserializationError error = deserializeJson(doc, json);
|
||||||
if (error) {
|
if (error)
|
||||||
if (e) {
|
{
|
||||||
|
if (e)
|
||||||
|
{
|
||||||
SerialPrint("E", F("jsonWrite"), error.f_str());
|
SerialPrint("E", F("jsonWrite"), error.f_str());
|
||||||
jsonErrorDetected();
|
jsonErrorDetected();
|
||||||
}
|
}
|
||||||
@@ -316,11 +406,14 @@ String jsonWriteInt(String& json, String name, int value, bool e) {
|
|||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
String jsonWriteFloat(String& json, String name, float value, bool e) {
|
String jsonWriteFloat(String &json, String name, float value, bool e)
|
||||||
|
{
|
||||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||||
DeserializationError error = deserializeJson(doc, json);
|
DeserializationError error = deserializeJson(doc, json);
|
||||||
if (error) {
|
if (error)
|
||||||
if (e) {
|
{
|
||||||
|
if (e)
|
||||||
|
{
|
||||||
SerialPrint("E", F("jsonWrite"), error.f_str());
|
SerialPrint("E", F("jsonWrite"), error.f_str());
|
||||||
jsonErrorDetected();
|
jsonErrorDetected();
|
||||||
}
|
}
|
||||||
@@ -331,7 +424,8 @@ String jsonWriteFloat(String& json, String name, float value, bool e) {
|
|||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
void jsonErrorDetected() {
|
void jsonErrorDetected()
|
||||||
|
{
|
||||||
// пример как отправить ошибку с количеством
|
// пример как отправить ошибку с количеством
|
||||||
// jsonWriteInt(errorsHeapJson, F("jse2"), 1);
|
// jsonWriteInt(errorsHeapJson, F("jse2"), 1);
|
||||||
// int number = jsonReadInt(errorsHeapJson, F("jse2n"));
|
// int number = jsonReadInt(errorsHeapJson, F("jse2n"));
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ void routerConnect()
|
|||||||
WiFi.mode(WIFI_STA);
|
WiFi.mode(WIFI_STA);
|
||||||
byte triesOne = TRIESONE;
|
byte triesOne = TRIESONE;
|
||||||
|
|
||||||
JsonArray _ssidList;
|
std::vector<String> _ssidList;
|
||||||
JsonArray _passwordList;
|
std::vector<String> _passwordList;
|
||||||
jsonReadArray(settingsFlashJson, "routerssid", _ssidList);
|
jsonReadArray(settingsFlashJson, "routerssid", _ssidList);
|
||||||
jsonReadArray(settingsFlashJson, "routerpass", _passwordList);
|
jsonReadArray(settingsFlashJson, "routerpass", _passwordList);
|
||||||
if (_ssidList.size() > 1)
|
if (_ssidList.size() > 1)
|
||||||
@@ -24,7 +24,7 @@ void routerConnect()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
WiFi.begin(_ssidList[0].as<const char*>(), _passwordList[0].as<const char*>());
|
WiFi.begin(_ssidList[0].c_str(), _passwordList[0].c_str());
|
||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
WiFi.setTxPower(WIFI_POWER_19_5dBm);
|
WiFi.setTxPower(WIFI_POWER_19_5dBm);
|
||||||
#else
|
#else
|
||||||
@@ -34,11 +34,11 @@ void routerConnect()
|
|||||||
String _password;
|
String _password;
|
||||||
for (int8_t i = 0; i < _ssidList.size(); i++)
|
for (int8_t i = 0; i < _ssidList.size(); i++)
|
||||||
{
|
{
|
||||||
_ssid = _ssid + _ssidList[i].as<String>() + "; ";
|
_ssid = _ssid + _ssidList[i] + "; ";
|
||||||
}
|
}
|
||||||
for (int8_t i = 0; i < _passwordList.size(); i++)
|
for (int8_t i = 0; i < _passwordList.size(); i++)
|
||||||
{
|
{
|
||||||
_password = _password + _passwordList[i].as<String>() + "; ";
|
_password = _password + _passwordList[i] + "; ";
|
||||||
}
|
}
|
||||||
SerialPrint("i", "WIFI", "ssid list: " + _ssid);
|
SerialPrint("i", "WIFI", "ssid list: " + _ssid);
|
||||||
SerialPrint("i", "WIFI", "pass list: " + _password);
|
SerialPrint("i", "WIFI", "pass list: " + _password);
|
||||||
@@ -48,9 +48,9 @@ void routerConnect()
|
|||||||
triesOne = TRIESONE;
|
triesOne = TRIESONE;
|
||||||
if (WiFi.status() == WL_CONNECTED)
|
if (WiFi.status() == WL_CONNECTED)
|
||||||
break;
|
break;
|
||||||
WiFi.begin(_ssidList[i].as<const char*>(), _passwordList[i].as<const char*>());
|
WiFi.begin(_ssidList[i].c_str(), _passwordList[i].c_str());
|
||||||
SerialPrint("i", "WIFI", "ssid connect: " + _ssidList[i].as<String>());
|
SerialPrint("i", "WIFI", "ssid connect: " + _ssidList[i]);
|
||||||
SerialPrint("i", "WIFI", "pass connect: " + _passwordList[i].as<String>());
|
SerialPrint("i", "WIFI", "pass connect: " + _passwordList[i]);
|
||||||
while (--triesOne && WiFi.status() != WL_CONNECTED)
|
while (--triesOne && WiFi.status() != WL_CONNECTED)
|
||||||
{
|
{
|
||||||
// SerialPrint("i", "WIFI", ": " + String((int)WiFi.status()));
|
// SerialPrint("i", "WIFI", ": " + String((int)WiFi.status()));
|
||||||
@@ -109,11 +109,11 @@ bool startAPMode()
|
|||||||
WIFI_SCAN, 30 * 1000,
|
WIFI_SCAN, 30 * 1000,
|
||||||
[&](void *)
|
[&](void *)
|
||||||
{
|
{
|
||||||
JsonArray jArray;
|
std::vector<String> jArray;
|
||||||
jsonReadArray(settingsFlashJson, "routerssid", jArray);
|
jsonReadArray(settingsFlashJson, "routerssid", jArray);
|
||||||
for (int8_t i = 0; i < jArray.size(); i++)
|
for (int8_t i = 0; i < jArray.size(); i++)
|
||||||
{
|
{
|
||||||
SerialPrint("i", "WIFI", "scanning for " + jArray[i].as<String>());
|
SerialPrint("i", "WIFI", "scanning for " + jArray[i]);
|
||||||
}
|
}
|
||||||
if (RouterFind(jArray))
|
if (RouterFind(jArray))
|
||||||
{
|
{
|
||||||
@@ -127,7 +127,7 @@ bool startAPMode()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean RouterFind(JsonArray jArray)
|
boolean RouterFind(std::vector<String> jArray)
|
||||||
{
|
{
|
||||||
bool res = false;
|
bool res = false;
|
||||||
int n = WiFi.scanComplete();
|
int n = WiFi.scanComplete();
|
||||||
|
|||||||
Reference in New Issue
Block a user