Корпус тензодатчика в вентиляцию
parent
69d0fcb68b
commit
c6348a6706
|
@ -10,7 +10,6 @@
|
||||||
#include <PubSubClient.h> //Mtqq
|
#include <PubSubClient.h> //Mtqq
|
||||||
#include <ArduinoJson.h> //Упакова в JSon - удобная библиотека
|
#include <ArduinoJson.h> //Упакова в JSon - удобная библиотека
|
||||||
#include <ESPmDNS.h>
|
#include <ESPmDNS.h>
|
||||||
#include "esp32-hal-ledc.h"
|
|
||||||
|
|
||||||
#define Fpin 22
|
#define Fpin 22
|
||||||
#define Bpin 19
|
#define Bpin 19
|
||||||
|
@ -19,10 +18,7 @@
|
||||||
#define TRIGGER_PIN 39
|
#define TRIGGER_PIN 39
|
||||||
unsigned int VersionSW = 4;
|
unsigned int VersionSW = 4;
|
||||||
|
|
||||||
const int freq = 5000;
|
|
||||||
const int ledChannel1 = 0;
|
|
||||||
const int ledChannel2 = 1;
|
|
||||||
const int resolution = 8;
|
|
||||||
|
|
||||||
//3 - Первый код для анемостата
|
//3 - Первый код для анемостата
|
||||||
|
|
||||||
|
@ -33,14 +29,14 @@ String JsonData;
|
||||||
StaticJsonDocument<200> doc, docResult;
|
StaticJsonDocument<200> doc, docResult;
|
||||||
|
|
||||||
WiFiClient espClient;
|
WiFiClient espClient;
|
||||||
PubSubClient MqttClient(espClient);
|
PubSubClient MqttClient(espClient);
|
||||||
IPAddress IpMqtt;
|
IPAddress IpMqtt;
|
||||||
|
|
||||||
WiFiUDP ntpUDP;
|
WiFiUDP ntpUDP;
|
||||||
NTPClient timeClient(ntpUDP, "192.168.89.210", 0, 20000); //Собственно сервер времени смещение и частоат запроса, но он вручную
|
NTPClient timeClient(ntpUDP, "192.168.89.210", 0, 20000); //Собственно сервер времени смещение и частоат запроса, но он вручную
|
||||||
const PROGMEM char *willmess = "{\"conn\":\"err\"}";
|
const PROGMEM char *willmess = "{\"conn\":\"err\"}";
|
||||||
const char *mqttHostName = "cctv.automation.art"; //Хостнейм брокера metrics.local cctv.automation.art //192.168.89.210
|
const char *mqttHostName = "metrics"; //Хостнейм брокера metrics.local cctv.automation.art //192.168.89.210
|
||||||
unsigned int mqttPort = 8889; //Порт брокера 1883 8889
|
unsigned int mqttPort = 1883; //Порт брокера 1883 8889
|
||||||
|
|
||||||
String getMacAddress();
|
String getMacAddress();
|
||||||
String macc = getMacAddress();
|
String macc = getMacAddress();
|
||||||
|
@ -54,17 +50,20 @@ int stateResistor = 0;
|
||||||
|
|
||||||
const char *mqttIPHost; //тут хранится IP хоста по хостнейму
|
const char *mqttIPHost; //тут хранится IP хоста по хостнейму
|
||||||
unsigned long timingUpdate = 0, timingReqSensor = 0, timingSendMqtt = 0; //Таймеры для millis()
|
unsigned long timingUpdate = 0, timingReqSensor = 0, timingSendMqtt = 0; //Таймеры для millis()
|
||||||
int PROGMEM nextM5Update = 450000, nextMqttSend = 10000; //каждые 7.5 минут запрос обновления с сервера
|
int PROGMEM nextM5Update = 450000, nextMqttSend = 20000; //каждые 7.5 минут запрос обновления с сервера
|
||||||
|
|
||||||
bool mqttSendFlag = false;
|
bool mqttSendFlag = false;
|
||||||
int reqCounter = 0;
|
int reqCounter = 0;
|
||||||
long rssi = 0, minRes = 1450, maxRes = 2600;
|
long rssi = 0, minRes=1480, maxRes=2600;
|
||||||
char bufTopic[140], bufWillTopic[150], bufSetTopic[150];
|
char bufTopic[140], bufWillTopic[150], bufSetTopic[150];
|
||||||
|
|
||||||
|
|
||||||
int moveAnemo(byte speed, byte percent);
|
int moveAnemo(byte speed, byte percent);
|
||||||
int setMotor(bool Finput, int Binput);
|
int setMotor(bool Finput, int Binput);
|
||||||
void callback(char *topic, byte *payload, unsigned int length);
|
void callback(char *topic, byte *payload, unsigned int length);
|
||||||
int disconnectMQTT();
|
int disconnectMQTT();
|
||||||
|
int SendMqttReq(bool sendVal, bool sendStatus, byte statusConn);
|
||||||
|
|
||||||
|
|
||||||
void ledset(byte color = 0)
|
void ledset(byte color = 0)
|
||||||
{
|
{
|
||||||
|
@ -144,7 +143,7 @@ int setMqttServer(const char *mqttHostNameF, unsigned int mqttPortF)
|
||||||
Serial.println(ipaddr);
|
Serial.println(ipaddr);
|
||||||
|
|
||||||
if (ipaddr.toString() == "0.0.0.0")
|
if (ipaddr.toString() == "0.0.0.0")
|
||||||
{
|
{
|
||||||
//Запрос к ДНС по адресу сайта
|
//Запрос к ДНС по адресу сайта
|
||||||
int err = WiFi.hostByName(mqttHostNameF, ipaddr);
|
int err = WiFi.hostByName(mqttHostNameF, ipaddr);
|
||||||
////real internal timeout in lwip library is 14[s]
|
////real internal timeout in lwip library is 14[s]
|
||||||
|
@ -222,13 +221,13 @@ void callback(char *topic, byte *payload, unsigned int length)
|
||||||
setSpeedAnemo = (byte)docResult["speed"]; //speed
|
setSpeedAnemo = (byte)docResult["speed"]; //speed
|
||||||
|
|
||||||
moveAnemo(setSpeedAnemo, setPercent);
|
moveAnemo(setSpeedAnemo, setPercent);
|
||||||
}
|
}
|
||||||
|
|
||||||
int nowPercent(int analogStatus)
|
int nowPercent(int analogStatus)
|
||||||
{
|
{
|
||||||
|
|
||||||
Serial.print("Percent NOW: ");
|
Serial.print("Percent NOW: ");
|
||||||
int percentNow = map(analogStatus, minRes, maxRes, 0, 100);
|
int percentNow = map(analogStatus, minRes, maxRes, 0, 100);
|
||||||
Serial.print(percentNow);
|
Serial.print(percentNow);
|
||||||
Serial.println(" %");
|
Serial.println(" %");
|
||||||
|
|
||||||
|
@ -263,7 +262,7 @@ int moveAnemo(byte speed, byte percent)
|
||||||
while (setResist <= stateResistor)
|
while (setResist <= stateResistor)
|
||||||
{
|
{
|
||||||
stateResistor = analogRead(Resist);
|
stateResistor = analogRead(Resist);
|
||||||
Serial.print("Now: ");
|
Serial.print("Now: ");
|
||||||
Serial.print(map(stateResistor, minRes, maxRes, 0, 100));
|
Serial.print(map(stateResistor, minRes, maxRes, 0, 100));
|
||||||
Serial.println(" %");
|
Serial.println(" %");
|
||||||
delay(200);
|
delay(200);
|
||||||
|
@ -281,8 +280,9 @@ int moveAnemo(byte speed, byte percent)
|
||||||
delay(200);
|
delay(200);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setMotor(false, false);
|
setMotor(false, false);
|
||||||
|
SendMqttReq(true,true,1);
|
||||||
|
|
||||||
// 0 - 1460
|
// 0 - 1460
|
||||||
// 10 - 1535 - 1547
|
// 10 - 1535 - 1547
|
||||||
|
@ -294,8 +294,8 @@ int moveAnemo(byte speed, byte percent)
|
||||||
// 70 - 2261 - 2273
|
// 70 - 2261 - 2273
|
||||||
// 80 - 2382 - 2394
|
// 80 - 2382 - 2394
|
||||||
// 90 - 2503 - 2515
|
// 90 - 2503 - 2515
|
||||||
// 100 -2624 - 2640
|
// 100 -2624 - 2640
|
||||||
|
|
||||||
//1420 - закрыто
|
//1420 - закрыто
|
||||||
//2630 - открыто
|
//2630 - открыто
|
||||||
|
|
||||||
|
@ -438,14 +438,13 @@ int SendMqttReq(bool sendVal = true, bool sendStatus = true, byte statusConn = 1
|
||||||
|
|
||||||
doc["analog"] = nowResist();
|
doc["analog"] = nowResist();
|
||||||
doc["percent"] = nowPercent(nowResist());
|
doc["percent"] = nowPercent(nowResist());
|
||||||
doc["co2"] = "";
|
|
||||||
|
|
||||||
doc["ts"] = timeNow;
|
doc["ts"] = timeNow;
|
||||||
|
|
||||||
serializeJson(doc, JsonData);
|
serializeJson(doc, JsonData);
|
||||||
doc.remove("ts");
|
doc.remove("ts");
|
||||||
doc.remove("analog");
|
doc.remove("analog");
|
||||||
doc.remove("percent");
|
doc.remove("percent");
|
||||||
doc.clear();
|
doc.clear();
|
||||||
doc.garbageCollect();
|
doc.garbageCollect();
|
||||||
|
|
||||||
|
@ -482,8 +481,8 @@ int SendMqttReq(bool sendVal = true, bool sendStatus = true, byte statusConn = 1
|
||||||
doc["rssi"] = rssi;
|
doc["rssi"] = rssi;
|
||||||
doc["bsid"] = WiFi.BSSIDstr();
|
doc["bsid"] = WiFi.BSSIDstr();
|
||||||
doc["ts"] = timeNow;
|
doc["ts"] = timeNow;
|
||||||
doc["exp"] = timeNow + 11000;
|
doc["exp"] = timeNow + 20000;
|
||||||
doc["sv"] = VersionSW;
|
doc["sv"] = VersionSW;
|
||||||
|
|
||||||
JsonData = "";
|
JsonData = "";
|
||||||
serializeJson(doc, JsonData);
|
serializeJson(doc, JsonData);
|
||||||
|
@ -549,18 +548,12 @@ void setup()
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
Serial.setDebugOutput(true);
|
Serial.setDebugOutput(true);
|
||||||
M5.begin(true, false, true);
|
M5.begin(true, false, true);
|
||||||
|
|
||||||
delay(50);
|
delay(50);
|
||||||
pinMode(TRIGGER_PIN, INPUT);
|
pinMode(TRIGGER_PIN, INPUT);
|
||||||
|
|
||||||
pinMode(Fpin, OUTPUT);
|
pinMode(Fpin, OUTPUT);
|
||||||
pinMode(Bpin, OUTPUT);
|
pinMode(Bpin, OUTPUT);
|
||||||
ledcSetup(ledChannel1, freq, resolution);
|
|
||||||
ledcSetup(ledChannel2, freq, resolution);
|
|
||||||
|
|
||||||
ledcAttachPin(Fpin, ledChannel1);
|
|
||||||
ledcAttachPin(Bpin, ledChannel2);
|
|
||||||
|
|
||||||
|
|
||||||
setMotor(false, false);
|
setMotor(false, false);
|
||||||
|
|
||||||
|
@ -607,7 +600,7 @@ void setup()
|
||||||
}
|
}
|
||||||
|
|
||||||
setMqttServer(mqttHostName, mqttPort);
|
setMqttServer(mqttHostName, mqttPort);
|
||||||
nowPercent(nowResist());
|
nowPercent(nowResist());
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
|
@ -627,11 +620,11 @@ void loop()
|
||||||
|
|
||||||
stateResistor = analogRead(Resist);
|
stateResistor = analogRead(Resist);
|
||||||
|
|
||||||
// if (millis() - timingSendMqtt > nextMqttSend)
|
if (millis() - timingSendMqtt > nextMqttSend)
|
||||||
// {
|
{
|
||||||
// SendMqttReq();
|
SendMqttReq(true,true,1);
|
||||||
// timingSendMqtt = millis();
|
timingSendMqtt = millis();
|
||||||
// }
|
}
|
||||||
|
|
||||||
// 40 секунд и происходит сброс настроек WIFI
|
// 40 секунд и происходит сброс настроек WIFI
|
||||||
if (M5.Btn.wasReleasefor(40000))
|
if (M5.Btn.wasReleasefor(40000))
|
||||||
|
@ -664,19 +657,14 @@ int setMotor(bool Finput, int Binput)
|
||||||
|
|
||||||
if (Finput == true && Binput == false)
|
if (Finput == true && Binput == false)
|
||||||
{
|
{
|
||||||
|
digitalWrite(Fpin, HIGH);
|
||||||
// digitalWrite(Fpin, HIGH);
|
|
||||||
|
|
||||||
ledcWrite(ledChannel1, 200);
|
|
||||||
digitalWrite(Bpin, LOW);
|
digitalWrite(Bpin, LOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Finput == false && Binput == true)
|
if (Finput == false && Binput == true)
|
||||||
{
|
{
|
||||||
digitalWrite(Fpin, LOW);
|
digitalWrite(Fpin, LOW);
|
||||||
|
digitalWrite(Bpin, HIGH);
|
||||||
ledcWrite(ledChannel2, 200);
|
|
||||||
// digitalWrite(Bpin, HIGH);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//stop
|
//stop
|
||||||
|
|
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
After Width: | Height: | Size: 111 KiB |
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
After Width: | Height: | Size: 1.8 KiB |
Binary file not shown.
After Width: | Height: | Size: 127 KiB |
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue