Датчики СО2. Новые + дисплей

master
SmartUA 2021-07-13 15:10:07 +03:00
parent 3b85e85006
commit 92e78629e0
10 changed files with 45760 additions and 108 deletions

1010
NewSensor/3D_2corpus2.stl Normal file

File diff suppressed because it is too large Load Diff

19546
NewSensor/3D_3corpus2.stl Normal file

File diff suppressed because it is too large Load Diff

24726
NewSensor/3D_corus.stl Normal file

File diff suppressed because it is too large Load Diff

254
NewSensor/3D_corus2.stl Normal file
View File

@ -0,0 +1,254 @@
solid Untitled
facet normal 0.0 0.0 1.0
outer loop
vertex 119.70438423244394 91.35230514530528 7.0
vertex 95.16191951807465 92.35230514530528 7.0
vertex 95.16191951807465 91.35230514530528 7.0
endloop
endfacet
facet normal 0.0 0.0 1.0
outer loop
vertex 95.16191951807465 92.35230514530528 7.0
vertex 119.70438423244394 91.35230514530528 7.0
vertex 119.70438423244394 92.35230514530528 7.0
endloop
endfacet
facet normal 0.0 1.0 0.0
outer loop
vertex 95.16191951807465 93.35230514530528 8.999999999999998
vertex 119.70438423244394 93.35230514530528 0.0
vertex 95.16191951807465 93.35230514530528 0.0
endloop
endfacet
facet normal 0.0 1.0 0.0
outer loop
vertex 119.70438423244394 93.35230514530528 0.0
vertex 95.16191951807465 93.35230514530528 8.999999999999998
vertex 119.70438423244394 93.35230514530528 8.999999999999998
endloop
endfacet
facet normal -1.0 -2.945697472215645e-15 -1.7961569952534367e-15
outer loop
vertex 95.16191951807465 93.35230514530528 8.999999999999998
vertex 95.16191951807465 92.35230514530528 7.0
vertex 95.16191951807465 92.35230514530528 8.999999999999998
endloop
endfacet
facet normal -1.0 -2.945697472215645e-15 -1.7961569952534367e-15
outer loop
vertex 95.16191951807465 91.35230514530528 7.999999999999999
vertex 95.16191951807468 90.35230514530528 0.9999999999999999
vertex 95.16191951807465 90.35230514530528 7.999999999999999
endloop
endfacet
facet normal -1.0 -2.945697472215645e-15 -1.7961569952534367e-15
outer loop
vertex 95.16191951807468 90.35230514530528 0.9999999999999999
vertex 95.16191951807465 91.35230514530528 7.999999999999999
vertex 95.16191951807468 91.35230514530528 0.9999999999999999
endloop
endfacet
facet normal -1.0 -2.945697472215645e-15 -1.7961569952534367e-15
outer loop
vertex 95.16191951807468 91.35230514530528 0.9999999999999999
vertex 95.16191951807465 91.35230514530528 7.999999999999999
vertex 95.16191951807465 91.35230514530528 7.0
endloop
endfacet
facet normal -1.0 -2.945697472215645e-15 -1.7961569952534367e-15
outer loop
vertex 95.16191951807468 91.35230514530528 0.9999999999999999
vertex 95.16191951807465 91.35230514530528 7.0
vertex 95.16191951807465 92.35230514530528 7.0
endloop
endfacet
facet normal -1.0 -2.945697472215645e-15 -1.7961569952534367e-15
outer loop
vertex 95.16191951807468 91.35230514530528 0.9999999999999999
vertex 95.16191951807465 92.35230514530528 7.0
vertex 95.16191951807468 91.35230514530528 0.0
endloop
endfacet
facet normal -1.0 -2.945697472215645e-15 -1.7961569952534367e-15
outer loop
vertex 95.16191951807468 91.35230514530528 0.0
vertex 95.16191951807465 92.35230514530528 7.0
vertex 95.16191951807465 93.35230514530528 0.0
endloop
endfacet
facet normal -1.0 -2.945697472215645e-15 -1.7961569952534367e-15
outer loop
vertex 95.16191951807465 93.35230514530528 0.0
vertex 95.16191951807465 92.35230514530528 7.0
vertex 95.16191951807465 93.35230514530528 8.999999999999998
endloop
endfacet
facet normal 0.0 0.0 1.0
outer loop
vertex 119.70438423244394 90.35230514530528 7.999999999999999
vertex 95.16191951807465 91.35230514530528 7.999999999999999
vertex 95.16191951807465 90.35230514530528 7.999999999999999
endloop
endfacet
facet normal 0.0 0.0 1.0
outer loop
vertex 95.16191951807465 91.35230514530528 7.999999999999999
vertex 119.70438423244394 90.35230514530528 7.999999999999999
vertex 119.70438423244394 91.35230514530528 7.999999999999999
endloop
endfacet
facet normal 0.0 0.0 -1.0
outer loop
vertex 119.70438423244394 93.35230514530528 0.0
vertex 95.16191951807468 91.35230514530528 0.0
vertex 95.16191951807465 93.35230514530528 0.0
endloop
endfacet
facet normal 0.0 0.0 -1.0
outer loop
vertex 95.16191951807468 91.35230514530528 0.0
vertex 119.70438423244394 93.35230514530528 0.0
vertex 119.70438423244394 91.35230514530528 0.0
endloop
endfacet
facet normal 1.0 0.0 0.0
outer loop
vertex 119.70438423244394 91.35230514530528 0.9999999999999999
vertex 119.70438423244394 90.35230514530528 7.999999999999999
vertex 119.70438423244394 90.35230514530528 0.9999999999999999
endloop
endfacet
facet normal 1.0 0.0 0.0
outer loop
vertex 119.70438423244394 90.35230514530528 7.999999999999999
vertex 119.70438423244394 91.35230514530528 0.9999999999999999
vertex 119.70438423244394 91.35230514530528 7.999999999999999
endloop
endfacet
facet normal 1.0 0.0 0.0
outer loop
vertex 119.70438423244394 91.35230514530528 7.999999999999999
vertex 119.70438423244394 91.35230514530528 0.9999999999999999
vertex 119.70438423244394 91.35230514530528 7.0
endloop
endfacet
facet normal 1.0 0.0 0.0
outer loop
vertex 119.70438423244394 93.35230514530528 0.0
vertex 119.70438423244394 91.35230514530528 0.9999999999999999
vertex 119.70438423244394 91.35230514530528 0.0
endloop
endfacet
facet normal 1.0 0.0 0.0
outer loop
vertex 119.70438423244394 91.35230514530528 0.9999999999999999
vertex 119.70438423244394 93.35230514530528 0.0
vertex 119.70438423244394 91.35230514530528 7.0
endloop
endfacet
facet normal 1.0 0.0 0.0
outer loop
vertex 119.70438423244394 91.35230514530528 7.0
vertex 119.70438423244394 93.35230514530528 0.0
vertex 119.70438423244394 92.35230514530528 7.0
endloop
endfacet
facet normal 1.0 0.0 0.0
outer loop
vertex 119.70438423244394 92.35230514530528 7.0
vertex 119.70438423244394 93.35230514530528 0.0
vertex 119.70438423244394 92.35230514530528 8.999999999999998
endloop
endfacet
facet normal 1.0 0.0 0.0
outer loop
vertex 119.70438423244394 92.35230514530528 8.999999999999998
vertex 119.70438423244394 93.35230514530528 0.0
vertex 119.70438423244394 93.35230514530528 8.999999999999998
endloop
endfacet
facet normal 0.0 0.0 1.0
outer loop
vertex 119.70438423244394 92.35230514530528 8.999999999999998
vertex 95.16191951807465 93.35230514530528 8.999999999999998
vertex 95.16191951807465 92.35230514530528 8.999999999999998
endloop
endfacet
facet normal 0.0 0.0 1.0
outer loop
vertex 95.16191951807465 93.35230514530528 8.999999999999998
vertex 119.70438423244394 92.35230514530528 8.999999999999998
vertex 119.70438423244394 93.35230514530528 8.999999999999998
endloop
endfacet
facet normal -0.0 -1.0 -0.0
outer loop
vertex 119.70438423244394 92.35230514530528 8.999999999999998
vertex 95.16191951807465 92.35230514530528 7.0
vertex 119.70438423244394 92.35230514530528 7.0
endloop
endfacet
facet normal -0.0 -1.0 -0.0
outer loop
vertex 95.16191951807465 92.35230514530528 7.0
vertex 119.70438423244394 92.35230514530528 8.999999999999998
vertex 95.16191951807465 92.35230514530528 8.999999999999998
endloop
endfacet
facet normal 0.0 1.0 0.0
outer loop
vertex 95.16191951807465 91.35230514530528 7.999999999999999
vertex 119.70438423244394 91.35230514530528 7.0
vertex 95.16191951807465 91.35230514530528 7.0
endloop
endfacet
facet normal 0.0 1.0 0.0
outer loop
vertex 119.70438423244394 91.35230514530528 7.0
vertex 95.16191951807465 91.35230514530528 7.999999999999999
vertex 119.70438423244394 91.35230514530528 7.999999999999999
endloop
endfacet
facet normal 0.0 -1.0 0.0
outer loop
vertex 119.70438423244394 90.35230514530528 7.999999999999999
vertex 95.16191951807468 90.35230514530528 0.9999999999999999
vertex 119.70438423244394 90.35230514530528 0.9999999999999999
endloop
endfacet
facet normal 0.0 -1.0 0.0
outer loop
vertex 95.16191951807468 90.35230514530528 0.9999999999999999
vertex 119.70438423244394 90.35230514530528 7.999999999999999
vertex 95.16191951807465 90.35230514530528 7.999999999999999
endloop
endfacet
facet normal 0.0 -1.0 0.0
outer loop
vertex 119.70438423244394 91.35230514530528 0.9999999999999999
vertex 95.16191951807468 91.35230514530528 0.0
vertex 119.70438423244394 91.35230514530528 0.0
endloop
endfacet
facet normal 0.0 -1.0 0.0
outer loop
vertex 95.16191951807468 91.35230514530528 0.0
vertex 119.70438423244394 91.35230514530528 0.9999999999999999
vertex 95.16191951807468 91.35230514530528 0.9999999999999999
endloop
endfacet
facet normal 0.0 0.0 -1.0
outer loop
vertex 119.70438423244394 91.35230514530528 0.9999999999999999
vertex 95.16191951807468 90.35230514530528 0.9999999999999999
vertex 95.16191951807468 91.35230514530528 0.9999999999999999
endloop
endfacet
facet normal 0.0 0.0 -1.0
outer loop
vertex 95.16191951807468 90.35230514530528 0.9999999999999999
vertex 119.70438423244394 91.35230514530528 0.9999999999999999
vertex 119.70438423244394 90.35230514530528 0.9999999999999999
endloop
endfacet
endsolid Untitled

BIN
NewSensor/Untitled.skb Normal file

Binary file not shown.

BIN
NewSensor/Untitled.skp Normal file

Binary file not shown.

BIN
scd30mh/CO2.bin Normal file

Binary file not shown.

View File

@ -18,28 +18,42 @@
#include <ArduinoJson.h> //Упакова в JSon - удобная библиотека
#include <ESPmDNS.h>
#include <Wire.h>
#include "MHZ19.h"
#include <SoftwareSerial.h>
#include "SparkFun_SCD30_Arduino_Library.h" //Click here to get the library: http://librarymanager/All#SparkFun_SCD30
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET 4
//Наша кнопочка при нажатии на которую произойдет вызов wifi менеджера и перезагрузка в станцию
#define TRIGGER_PIN 39
#define safetyPin 26
#define safetyPinOutput 32
#define RX_PIN 19
#define TX_PIN 22
#define BAUDRATE 9600
extern const unsigned char image_x[77], image_error[77], image_plus[77], image_connect[77], image_wifi[77];
#define i2cSDA 25
#define i2cSCL 21
unsigned int VersionSW = 13; //65536 Версия прошивки
byte errorID = 0;
MHZ19 myMHZ19;
SoftwareSerial mySerial(RX_PIN, TX_PIN);
unsigned int VersionSW = 17;
//17 - локальный брокер
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
WiFiManager wm; // обьект менеджера
Preferences OTApreferences; //Обьект хранения настроек хеша прошивки
String JsonData;
StaticJsonDocument<200> doc;
SCD30 airSensor;
SCD30 airSens30;
WiFiClient espClient;
PubSubClient MqttClient(espClient);
@ -49,7 +63,7 @@ WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "192.168.89.210", 0, 20000); //Собственно сервер времени смещение и частоат запроса, но он вручную
const PROGMEM char *willmess = "{\"conn\":\"err\"}";
const char *mqttHostName = "metrics"; //Хостнейм брокера metrics.local cctv.automation.art //192.168.89.210
unsigned int mqttPort = 1883; //Порт брокера 1883 8889
unsigned int mqttPort = 1883; //Порт брокера 1883 8889
String getMacAddress();
String macc = getMacAddress();
@ -57,67 +71,105 @@ String topicTemp = "aastudio/sens/" + macc + "/data/0";
String willTopicTemp = "aastudio/sens/" + macc + "/status";
const PROGMEM char *mqttLogin = "AA_Lab", *mqttPass = "automation.art$";
const char *mqttIPHost; //тут хранится IP хоста по хостнейму
const char *mqttIPHost; //тут хранится IP хоста по хостнейму
unsigned long timingUpdate, timingReqSensor, timingSendMqtt; //Таймеры для millis()
int PROGMEM nextM5Update = 450000; //каждые 7.5 минут запрос обновления с сервера //опрос датчиков раз в 10 секунд
int PROGMEM nextMqttSend = 1000; //Отправка
byte typeSensor=0;
int PROGMEM nextMqttSend = 10000; //Отправка
bool typeSensor = false, GlobalOled = false;
bool mqttSendFlag = false;
bool safetyStateNow = false, safetyStateOld = false;
int reqCounter = 0;
long rssi = 0;
int GlobalCo2 = 0;
char bufTopic[140], bufWillTopic[150], bufAngleTopic[150];
void ledset(byte color = 0)
{
M5.dis.setBrightness(60); //Половина яркости
switch (color)
{
case 2:
M5.dis.drawpix(0, 0xf00000); //Зеленый
break;
case 1:
M5.dis.drawpix(0, 0x00ff00); //Красный
break;
case 3:
M5.dis.drawpix(0, 0x0000ff); //Синий
break;
case 4:
M5.dis.drawpix(0, 0xffffff); //Белый
break;
case 5:
M5.dis.drawpix(0, 0xffec00); //желтый
break;
default:
M5.dis.clear();
break;
}
}
//Настройки
void setup()
{
// 1й - Просто датчик scd30
// 2й - Датчик золотой MH-z19
if(macc=="" || macc==""){ typeSensor=1; }
else if(macc=="" || macc=="") {typeSensor=2;}
if(typeSensor==1){
Wire.begin(21,25);
if (airSensor.begin() == false)
{
Serial.println("Air sensor not detected. Please check wiring. Freezing...");
while (1)
;
}
airSensor.setMeasurementInterval(4); //Change number of seconds between measurements: 2 to 1800 (30 minutes)
//My desk is ~1600m above sealevel
airSensor.setAltitudeCompensation(170); //Set altitude of the sensor in m
//Pressure in Boulder, CO is 24.65inHg or 834.74mBar
// airSensor.setAmbientPressure(835); //Current ambient pressure in mBar: 700 to 1200
float offset = airSensor.getTemperatureOffset();
Serial.print("Current temp offset: ");
Serial.print(offset, 2);
Serial.println("C");
//airSensor.setTemperatureOffset(5);
}
M5.begin(true, false, true);
M5.dis.setBrightness(30);
delay(50);
pinMode(TRIGGER_PIN, INPUT);
pinMode(safetyPinOutput, OUTPUT); // Установка пина на выход
digitalWrite(safetyPinOutput, HIGH); //Потому что он 3.3В а не 5 как на выходе рядом
pinMode(safetyPin, INPUT); //Пин датчика для работы
Serial.begin(115200);
Serial.setDebugOutput(true);
Wire.begin(32, 26);
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C))
{ // Address 0x3D for 128x64
GlobalOled = false;
}
else
{
GlobalOled = true;
display.display();
display.clearDisplay();
}
// 1й - Просто датчик scd30
// 2й - Датчик золотой MH-z19
if (macc == "94B97EAD9EDC" || macc == "94B97E8ADF7C")
{
typeSensor = true;
}
else if (macc == "24A160542E48" || macc == "94B97E8ADF80")
{
typeSensor = false;
}
if (typeSensor == true)
{
Wire.begin(i2cSDA, i2cSCL);
if (airSens30.begin() == false)
{
Serial.println("Air sensor not detected. Please check wiring. Freezing...");
}
airSens30.setMeasurementInterval(10); //Change number of seconds between measurements: 2 to 1800 (30 minutes)
airSens30.setAltitudeCompensation(324); //Set altitude of the sensor in m
// airSens30.setAmbientPressure(835); //Current ambient pressure in mBar: 700 to 1200
float offset = airSens30.getTemperatureOffset();
Serial.print("Current temp offset: ");
Serial.print(offset, 2);
Serial.println("C");
//airSens30.setTemperatureOffset(5);
}
else
{
mySerial.begin(BAUDRATE);
myMHZ19.begin(mySerial);
myMHZ19.autoCalibration(false);
}
M5.begin(true, false, true);
delay(50);
pinMode(TRIGGER_PIN, INPUT);
WiFi.mode(WIFI_STA);
delay(100);
@ -128,8 +180,6 @@ if(typeSensor==1){
topicTemp.toCharArray(bufTopic, topicTemp.length() + 1);
willTopicTemp.toCharArray(bufWillTopic, willTopicTemp.length() + 1);
disPreSet((uint8_t *)image_connect, 0, 0); //Идет настройка
// wm.resetSettings(); // wipe settings
std::vector<const char *> menu = {"wifi", "info", "param", "sep", "restart", "exit"};
@ -292,7 +342,6 @@ void checkButton()
OTApreferences.putString("mqttip", "0");
OTApreferences.end();
ESP.restart();
}
@ -304,15 +353,13 @@ void OTAUpdate()
bool flagOTA = false;
String keyOTA;
String payload;
OTApreferences.begin("ota-config");
if (WiFi.status() == WL_CONNECTED)
{
HTTPClient http;
String serverPath = "http://meteosence.s-host.net/airqa/airquality.php?meteopas=pGiy94nIoOftZ0Ik&mac=" + macc + "&meteodata=gethash";
String serverPath = "http://meteosence.s-host.net/airqa/airquality.php?meteopas=84sdi5239dfkg4&mac=" + macc + "&meteodata=gethash";
http.begin(serverPath.c_str());
int httpResponseCode = http.GET();
@ -342,15 +389,12 @@ void OTAUpdate()
//Serial.println("flagOTA = true;");
}
}
else
{
//Serial.println("Hosting return error HASH or error REQUEST");
errorID = 2;
}
}
else
{
errorID = 3;
Serial.print("Error code HTTP: ");
Serial.println(httpResponseCode);
}
@ -359,7 +403,7 @@ void OTAUpdate()
}
else
{
errorID = 4;
Serial.println("WiFi Disconnected");
}
@ -368,7 +412,7 @@ void OTAUpdate()
flagOTA = false;
//Serial.println("flagOTA = false;");
t_httpUpdate_return ret = ESPhttpUpdate.update("http://meteosence.s-host.net/airqa/safeatoms.bin");
t_httpUpdate_return ret = ESPhttpUpdate.update("http://meteosence.s-host.net/airqa/co2/co2.bin");
//После update ничего не происходит, такая вот особенность.
//Если все прошло хорошо, перезагрузка на новую прошивку
@ -438,13 +482,50 @@ int SendMqttReq(bool sendVal = true, bool sendStatus = true, byte statusConn = 1
if (sendVal == true)
{
doc["val"] = (int)safetyStateNow;
doc["ts"] = timeNow;
if (typeSensor == true)
{
doc["t"] = airSens30.getTemperature();
doc["h"] = airSens30.getHumidity();
GlobalCo2 = airSens30.getCO2();
doc["co2"] = GlobalCo2;
serializeJson(doc, JsonData);
doc["ts"] = timeNow;
doc.remove("val");
doc.remove("ts");
serializeJson(doc, JsonData);
doc.remove("ts");
doc.remove("t");
doc.remove("h");
doc.remove("co2");
}
else
{
int CO2 = 0;
int8_t Tempz19 = 0;
/* note: getCO2() default is command "CO2 Unlimited". This returns the correct CO2 reading even
if below background CO2 levels or above range (useful to validate sensor). You can use the
usual documented command with getCO2(false) */
CO2 = myMHZ19.getCO2(); // Request CO2 (as ppm)
GlobalCo2 = CO2;
Serial.print("CO2 (ppm): ");
Serial.println(CO2);
Tempz19 = myMHZ19.getTemperature(); // Request Temperature (as Celsius)
Serial.print("Temperature (C): ");
Serial.println(Tempz19);
doc["t"] = Tempz19;
doc["co2"] = CO2;
doc["ts"] = timeNow;
serializeJson(doc, JsonData);
doc.remove("ts");
doc.remove("t");
doc.remove("co2");
}
doc.clear();
doc.garbageCollect();
@ -478,12 +559,12 @@ int SendMqttReq(bool sendVal = true, bool sendStatus = true, byte statusConn = 1
default:
break;
}
doc["conn"] = conn;
doc["rssi"] = rssi;
doc["bsid"] = WiFi.BSSIDstr();
doc["ts"] = timeNow;
doc["exp"] = timeNow + 600;
doc["exp"] = timeNow + 600;
doc["sv"] = VersionSW;
JsonData = "";
@ -508,7 +589,7 @@ void reconnectMqtt()
while (!MqttClient.connected())
{
circle++;
if (circle == 7)
if (circle == 5)
{
break;
}
@ -544,16 +625,57 @@ void reconnectMqtt()
}
}
int printOled()
{
if (typeSensor == true)
{
Wire.begin(32, 26);
}
// if (display.begin(SSD1306_SWITCHCAPVCC, 0x3C))
// { // Address 0x3D for 128x64
Serial.println("PRINT OLED");
display.display();
delay(100);
// Clear the buffer
display.clearDisplay();
display.invertDisplay(true);
delay(500);
display.setTextSize(2);
display.setTextColor(SSD1306_WHITE);
display.setCursor(10, 20);
display.println(String(GlobalCo2)+String(" ppm"));
display.setTextSize(1);
display.setCursor(5, 5);
display.println(String("-CO2- "));
display.display(); // Show initial text
delay(100);
// }
if (typeSensor == true)
{
Wire.begin(i2cSDA, i2cSCL);
}
return 0;
}
void loop()
{
M5.update();
if (WiFi.status() != WL_CONNECTED)
{
{
Serial.println(WiFi.status());
disPreSet((uint8_t *)image_wifi, 0, 0);
errorID = 6;
delay(3000);
ESP.restart();
}
@ -564,23 +686,28 @@ void loop()
if (millis() - timingSendMqtt > nextMqttSend)
{
if (digitalRead(safetyPin) == HIGH)
{
safetyStateNow = true;
disPreSet((uint8_t *)image_plus, 0, 0);
}
else
{
safetyStateNow = false;
disPreSet((uint8_t *)image_x, 0, 0);
}
SendMqttReq();
if (safetyStateNow != safetyStateOld)
if (GlobalCo2 <= 320)
{
SendMqttReq();
safetyStateOld = safetyStateNow;
ledset(4); //Белый
}
else if (GlobalCo2 > 320 && GlobalCo2 <= 1000)
{
ledset(2); //зеленый
}
else if (GlobalCo2 > 1000 && GlobalCo2 <= 2000)
{
ledset(5); //желтый
}
else if (GlobalCo2 > 2000 && GlobalCo2 <= 5000)
{
ledset(1); //красный
}
if (GlobalOled == true)
{
printOled();
}
timingSendMqtt = millis();
}
@ -601,22 +728,11 @@ void loop()
}
//Таймер отправки данных в брокер
MqttClient.loop();
}
int disconnectMQTT()
{
MqttClient.disconnect();
return 0;
}
int disPreSet(uint8_t *image_what, int8_t x, int8_t y)
{
// M5.dis.fillpix(0x000000);
// M5.dis.clear();
delay(150);
M5.dis.displaybuff(image_what, x, y);
delay(200);
MqttClient.disconnect();
return 0;
}

Binary file not shown.

Binary file not shown.