mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
264 stable. Dallas bug fixed!
This commit is contained in:
@@ -42,7 +42,6 @@ int impulsEnterCounter = -1;
|
||||
|
||||
|
||||
// Sensors
|
||||
int8_t dallasEnterCounter = -1;
|
||||
String sensorReadingMap10sec;
|
||||
String sensorReadingMap30sec;
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "Global.h"
|
||||
#include "items/LoggingClass.h"
|
||||
#include "items/ImpulsOutClass.h"
|
||||
#include "items/SensorDallas.h"
|
||||
|
||||
void loadConfig() {
|
||||
configSetupJson = readFile("config.json", 4096);
|
||||
@@ -30,7 +31,10 @@ void Device_init() {
|
||||
|
||||
sensorReadingMap10sec = "";
|
||||
|
||||
dallasEnterCounter = -1;
|
||||
//======clear dallas params======
|
||||
if (mySensorDallas2 != nullptr) {
|
||||
mySensorDallas2->clear();
|
||||
}
|
||||
|
||||
//======clear logging params======
|
||||
if (myLogging != nullptr) {
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
#include "Module/Terminal.h"
|
||||
#include "Servo/Servos.h"
|
||||
|
||||
#include "items/SensorDallas.h"
|
||||
|
||||
Terminal *term = nullptr;
|
||||
|
||||
boolean but[NUM_BUTTONS];
|
||||
@@ -31,7 +33,7 @@ void cmd_init() {
|
||||
|
||||
sCmd.addCommand("analog-adc", analogAdc);
|
||||
sCmd.addCommand("ultrasonic-cm", ultrasonicCm);
|
||||
sCmd.addCommand("dallas-temp", dallasTemp);
|
||||
sCmd.addCommand("dallas-temp", dallas);
|
||||
|
||||
sCmd.addCommand("dht-temp", dhtTemp);
|
||||
sCmd.addCommand("dht-hum", dhtHum);
|
||||
|
||||
@@ -55,12 +55,14 @@ void addItem(String name) {
|
||||
}
|
||||
|
||||
void addPreset(String name) {
|
||||
String preset = readFile("presets/" + name + ".txt", 2024);
|
||||
Serial.println(name);
|
||||
String preset = readFile("presets/" + name + ".txt", 4048);
|
||||
Serial.println(preset);
|
||||
addFile(DEVICE_CONFIG_FILE, "\n" + preset);
|
||||
|
||||
name.replace(".c",".s");
|
||||
|
||||
String scenario = readFile("presets/" + name + ".txt", 2024);
|
||||
String scenario = readFile("presets/" + name + ".txt", 4048);
|
||||
removeFile(DEVICE_SCENARIO_FILE);
|
||||
addFile(DEVICE_SCENARIO_FILE, scenario);
|
||||
}
|
||||
|
||||
@@ -4,11 +4,11 @@
|
||||
#include "ItemsCmd.h"
|
||||
#include <Arduino.h>
|
||||
|
||||
SensorDallas::SensorDallas(unsigned long period, unsigned int pin, uint8_t deviceAddress, String key) {
|
||||
_period = period * 1000;
|
||||
SensorDallas::SensorDallas(unsigned long interval, unsigned int pin, unsigned int index, String key) {
|
||||
_interval = interval * 1000;
|
||||
_key = key;
|
||||
_pin = pin;
|
||||
_deviceAddress = deviceAddress;
|
||||
_index = index;
|
||||
|
||||
oneWire = new OneWire((uint8_t)_pin);
|
||||
sensors.setOneWire(oneWire);
|
||||
@@ -21,32 +21,34 @@ SensorDallas::~SensorDallas() {}
|
||||
void SensorDallas::loop() {
|
||||
currentMillis = millis();
|
||||
unsigned long difference = currentMillis - prevMillis;
|
||||
if (difference >= _period) {
|
||||
if (difference >= _interval) {
|
||||
prevMillis = millis();
|
||||
|
||||
readDallas();
|
||||
}
|
||||
}
|
||||
|
||||
void readDallas() {
|
||||
|
||||
void SensorDallas::readDallas() {
|
||||
sensors.requestTemperaturesByIndex(_index);
|
||||
float value = sensors.getTempCByIndex(_index);
|
||||
eventGen(_key, "");
|
||||
jsonWriteStr(configLiveJson, _key, String(value));
|
||||
publishStatus(_key, String(value));
|
||||
SerialPrint("I", "Sensor", "'" + _key + "' data: " + String(value));
|
||||
}
|
||||
|
||||
|
||||
MySensorDallasVector* mySensorDallas2 = nullptr;
|
||||
|
||||
//void logging() {
|
||||
// myLineParsing.update();
|
||||
// String loggingValueKey = myLineParsing.gval();
|
||||
// String key = myLineParsing.gkey();
|
||||
// String interv = myLineParsing.gint();
|
||||
// String maxcnt = myLineParsing.gcnt();
|
||||
// myLineParsing.clear();
|
||||
//
|
||||
// loggingKeyList += key + ",";
|
||||
//
|
||||
// static bool firstTime = true;
|
||||
// if (firstTime) myLogging = new MySensorDallasVector();
|
||||
// firstTime = false;
|
||||
// myLogging->push_back(SensorDallas(interv.toInt(), maxcnt.toInt(), loggingValueKey, key));
|
||||
//}
|
||||
void dallas() {
|
||||
myLineParsing.update();
|
||||
String interval = myLineParsing.gint();
|
||||
String pin = myLineParsing.gpin();
|
||||
String index = myLineParsing.gindex();
|
||||
String key = myLineParsing.gkey();
|
||||
myLineParsing.clear();
|
||||
|
||||
static bool firstTime = true;
|
||||
if (firstTime) mySensorDallas2 = new MySensorDallasVector();
|
||||
firstTime = false;
|
||||
mySensorDallas2->push_back(SensorDallas(interval.toInt(), pin.toInt(), index.toInt(), key));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
#include "ItemsCmd.h"
|
||||
#include "items/SensorDallasClass.h"
|
||||
//#ifdef SensorDallasEnabled
|
||||
//=========================================Модуль ультрозвукового дальномера==================================================================
|
||||
//dallas-temp;id;anydata;Сенсоры;Температура;order;pin;c[1]
|
||||
//=========================================================================================================================================
|
||||
SensorDallasClass mySensorDallas;
|
||||
void dallasTemp() {
|
||||
mySensorDallas.update();
|
||||
String key = mySensorDallas.gkey();
|
||||
sCmd.addCommand(key.c_str(), dallasReading);
|
||||
mySensorDallas.SensorDallasInit();
|
||||
mySensorDallas.clear();
|
||||
}
|
||||
|
||||
void dallasReading() {
|
||||
String key = sCmd.order();
|
||||
mySensorDallas.SensorDallasRead(key);
|
||||
}
|
||||
//#endif
|
||||
14
src/main.cpp
14
src/main.cpp
@@ -16,8 +16,8 @@
|
||||
#include "Utils/WebUtils.h"
|
||||
#include "items/ButtonInClass.h"
|
||||
#include "items/LoggingClass.h"
|
||||
|
||||
#include "items/ImpulsOutClass.h"
|
||||
#include "items/SensorDallas.h"
|
||||
|
||||
void not_async_actions();
|
||||
|
||||
@@ -101,11 +101,7 @@ void setup() {
|
||||
just_load = false;
|
||||
initialized = true; //this second POST makes the data to be processed (you don't need to connect as "keep-alive" for that to work)
|
||||
|
||||
//static bool firstTime = true;
|
||||
//if (firstTime) myImpulsOut = new MyImpulsOutVector();
|
||||
//firstTime = false;
|
||||
//myImpulsOut->push_back(ImpulsOutClass(500, 10, 13));
|
||||
//myImpulsOut->at(0).execute();
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
@@ -139,4 +135,10 @@ void loop() {
|
||||
myImpulsOut->at(i).loop();
|
||||
}
|
||||
}
|
||||
|
||||
if (mySensorDallas2 != nullptr) {
|
||||
for (unsigned int i = 0; i < mySensorDallas2->size(); i++) {
|
||||
mySensorDallas2->at(i).loop();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user