Корпус тензодатчика в вентиляцию

master
SmartUA 2021-08-07 17:22:41 +03:00
parent 69d0fcb68b
commit c6348a6706
14 changed files with 44591 additions and 44 deletions

View File

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

Binary file not shown.

0
anemostat/~WRL2371.tmp Normal file
View File

Binary file not shown.

9900
tenzo/1.stl Normal file

File diff suppressed because it is too large Load Diff

3642
tenzo/2.stl Normal file

File diff suppressed because it is too large Load Diff

BIN
tenzo/2354667.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 111 KiB

9956
tenzo/3.stl Normal file

File diff suppressed because it is too large Load Diff

3754
tenzo/4.stl Normal file

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

BIN
tenzo/Untitled.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 127 KiB

BIN
tenzo/Untitled.skb Normal file

Binary file not shown.

BIN
tenzo/Untitled.skp Normal file

Binary file not shown.

17307
tenzo/Untitled.xml Normal file

File diff suppressed because it is too large Load Diff