mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-30 20:09:14 +03:00
progress
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
|
#include "Utils/JsonUtils.h"
|
||||||
|
|
||||||
class LineParsing {
|
class LineParsing {
|
||||||
protected:
|
protected:
|
||||||
@@ -49,7 +50,7 @@ class LineParsing {
|
|||||||
if (i == 5) _order = sCmd.next();
|
if (i == 5) _order = sCmd.next();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 1; i < 6; i++) {
|
for (int i = 1; i < 10; i++) {
|
||||||
String arg = sCmd.next();
|
String arg = sCmd.next();
|
||||||
if (arg != "") {
|
if (arg != "") {
|
||||||
if (arg.indexOf("pin[") != -1) {
|
if (arg.indexOf("pin[") != -1) {
|
||||||
@@ -64,6 +65,12 @@ class LineParsing {
|
|||||||
if (arg.indexOf("db[") != -1) {
|
if (arg.indexOf("db[") != -1) {
|
||||||
_db = extractInner(arg);
|
_db = extractInner(arg);
|
||||||
}
|
}
|
||||||
|
if (arg.indexOf("map[") != -1) {
|
||||||
|
_map = extractInner(arg);
|
||||||
|
}
|
||||||
|
if (arg.indexOf("c[") != -1) {
|
||||||
|
_c = extractInner(arg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,6 +81,8 @@ class LineParsing {
|
|||||||
createWidgetClass(_descr, _page, _order, _file, _key);
|
createWidgetClass(_descr, _page, _order, _file, _key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//jsonWriteStr(configOptionJson, _key + "_pin", _pin);
|
||||||
|
|
||||||
String gkey() {
|
String gkey() {
|
||||||
return _key;
|
return _key;
|
||||||
}
|
}
|
||||||
@@ -90,14 +99,20 @@ class LineParsing {
|
|||||||
return _order;
|
return _order;
|
||||||
}
|
}
|
||||||
String gpin() {
|
String gpin() {
|
||||||
return _pin;
|
return _pin; //
|
||||||
}
|
}
|
||||||
String ginv() {
|
String ginv() {
|
||||||
return _inv;
|
return _inv; //
|
||||||
}
|
}
|
||||||
String gstate() {
|
String gstate() {
|
||||||
return _state;
|
return _state;
|
||||||
}
|
}
|
||||||
|
String gmap() {
|
||||||
|
return _map;
|
||||||
|
}
|
||||||
|
String gc() {
|
||||||
|
return _c;
|
||||||
|
}
|
||||||
|
|
||||||
void clear() {
|
void clear() {
|
||||||
_key = "";
|
_key = "";
|
||||||
@@ -150,4 +165,13 @@ class LineParsing {
|
|||||||
const String getWidgetFileClass(const String& name) {
|
const String getWidgetFileClass(const String& name) {
|
||||||
return "/widgets/" + name + ".json";
|
return "/widgets/" + name + ".json";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//String jsonWriteStr1(String& json, String name, String value) {
|
||||||
|
// DynamicJsonBuffer jsonBuffer;
|
||||||
|
// JsonObject& root = jsonBuffer.parseObject(json);
|
||||||
|
// root[name] = value;
|
||||||
|
// json = "";
|
||||||
|
// root.printTo(json);
|
||||||
|
// return json;
|
||||||
|
//}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -6,16 +6,11 @@
|
|||||||
#include "Class/SensorConverting.h"
|
#include "Class/SensorConverting.h"
|
||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
|
|
||||||
class SensorAnalog : public LineParsing,
|
class SensorAnalog : public SensorConverting {
|
||||||
public SensorConverting {
|
|
||||||
public:
|
public:
|
||||||
SensorAnalog() : LineParsing(),
|
SensorAnalog() : SensorConverting(){};
|
||||||
SensorConverting(){};
|
|
||||||
|
|
||||||
void SensorAnalogInit() {
|
void SensorAnalogInit(String key) {
|
||||||
//if (_pin != "") {
|
|
||||||
// pinMode(_pin.toInt(), INPUT);
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int SensorAnalogRead(String key, String pin) {
|
int SensorAnalogRead(String key, String pin) {
|
||||||
@@ -28,15 +23,16 @@ class SensorAnalog : public LineParsing,
|
|||||||
pinInt = pinInt;
|
pinInt = pinInt;
|
||||||
value = analogRead(A0);
|
value = analogRead(A0);
|
||||||
#endif
|
#endif
|
||||||
float valueFl;
|
|
||||||
//float valueFl = this->mapping(value);
|
//float valueFl = this->mapping(value);
|
||||||
// valueFl = this->correction(valueFl);
|
// valueFl = this->correction(valueFl);
|
||||||
|
|
||||||
eventGen(key, "");
|
value = this->mapping(key, value);
|
||||||
jsonWriteFloat(configLiveJson, key, valueFl);
|
|
||||||
MqttClient::publishStatus(key, String(valueFl));
|
|
||||||
|
|
||||||
Serial.println("[I] sensor '" + key + "' data: " + String(valueFl));
|
eventGen(key, "");
|
||||||
|
jsonWriteFloat(configLiveJson, key, value);
|
||||||
|
MqttClient::publishStatus(key, String(value));
|
||||||
|
|
||||||
|
Serial.println("[I] sensor '" + key + "' data: " + String(value));
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -9,20 +9,21 @@ class SensorConverting : public LineParsing {
|
|||||||
public:
|
public:
|
||||||
SensorConverting() : LineParsing(){};
|
SensorConverting() : LineParsing(){};
|
||||||
|
|
||||||
int mapping(int input) {
|
int mapping(String key, int input) {
|
||||||
if (_map != "") {
|
String map_ = jsonReadStr(configOptionJson, key + "_map");
|
||||||
_map.replace("map[", "");
|
if (map_ != "") {
|
||||||
_map.replace("]", "");
|
map_.replace("map[", "");
|
||||||
|
map_.replace("]", "");
|
||||||
input = map(input,
|
input = map(input,
|
||||||
selectFromMarkerToMarker(_map, ",", 0).toInt(),
|
selectFromMarkerToMarker(map_, ",", 0).toInt(),
|
||||||
selectFromMarkerToMarker(_map, ",", 1).toInt(),
|
selectFromMarkerToMarker(map_, ",", 1).toInt(),
|
||||||
selectFromMarkerToMarker(_map, ",", 2).toInt(),
|
selectFromMarkerToMarker(map_, ",", 2).toInt(),
|
||||||
selectFromMarkerToMarker(_map, ",", 3).toInt());
|
selectFromMarkerToMarker(map_, ",", 3).toInt());
|
||||||
}
|
}
|
||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
|
|
||||||
float correction(float input) {
|
float correction(String key, float input) {
|
||||||
_c.replace("c[", "");
|
_c.replace("c[", "");
|
||||||
_c.replace("]", "");
|
_c.replace("]", "");
|
||||||
float coef = _c.toFloat();
|
float coef = _c.toFloat();
|
||||||
|
|||||||
1
src/Class/LineParsing.cpp
Normal file
1
src/Class/LineParsing.cpp
Normal file
@@ -0,0 +1 @@
|
|||||||
|
#include "Class/LineParsing.h"
|
||||||
@@ -99,12 +99,14 @@ void analogAdc() {
|
|||||||
sCmd.addCommand(key.c_str(), analogReading);
|
sCmd.addCommand(key.c_str(), analogReading);
|
||||||
sensorReadingMap += key + ",";
|
sensorReadingMap += key + ",";
|
||||||
jsonWriteStr(configOptionJson, key + "_pin", pin);
|
jsonWriteStr(configOptionJson, key + "_pin", pin);
|
||||||
|
jsonWriteStr(configOptionJson, key + "_map", mySensorAnalog->gmap());
|
||||||
mySensorAnalog->clear();
|
mySensorAnalog->clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void analogReading() {
|
void analogReading() {
|
||||||
String key = sCmd.order();
|
String key = sCmd.order();
|
||||||
String pin = jsonReadStr(configOptionJson, key + "_pin");
|
String pin = jsonReadStr(configOptionJson, key + "_pin");
|
||||||
|
|
||||||
mySensorAnalog->SensorAnalogRead(key, pin);
|
mySensorAnalog->SensorAnalogRead(key, pin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user