Updated Wifi connection issue in v9

This commit is contained in:
Achim
2023-11-21 07:23:36 +07:00
parent feec04f42b
commit 91563ef836
2 changed files with 168 additions and 117 deletions

View File

@ -28,17 +28,29 @@ CC BY-SA 4.0 Attribution-ShareAlike 4.0 International License
*/
#include "PMS.h"
#include <HardwareSerial.h>
#include <Wire.h>
#include "s8_uart.h"
#include <HTTPClient.h>
#include <WiFiManager.h>
#include <Adafruit_NeoPixel.h>
#include <EEPROM.h>
#include "SHTSensor.h"
#include <SensirionI2CSgp41.h>
#include <NOxGasIndexAlgorithm.h>
#include <VOCGasIndexAlgorithm.h>
#include <U8g2lib.h>
#define DEBUG true
@ -114,7 +126,7 @@ int pm01 = -1;
int pm10 = -1;
int pm03PCount = -1;
const int tempHumInterval = 2500;
const int tempHumInterval = 5000;
unsigned long previousTempHum = 0;
float temp;
int hum;
@ -142,9 +154,11 @@ void setup() {
updateOLED2("Warming Up", "Serial Number:", String(getNormalizedMac()));
sgp41.begin(Wire);
delay(300);
sht.init(Wire);
sht.setAccuracy(SHTSensor::SHT_ACCURACY_MEDIUM);
//sht.setAccuracy(SHTSensor::SHT_ACCURACY_MEDIUM);
delay(300);
//init Watchdog
pinMode(2, OUTPUT);
@ -163,6 +177,14 @@ void setup() {
delay(400);
setConfig();
Serial.println("buttonConfig: " + String(buttonConfig));
updateOLED2("Press Button", "Now for", "LED Test");
delay(2000);
currentState = digitalRead(9);
if (currentState == LOW) {
ledTest();
}
updateOLED2("Press Button", "Now for", "Config Menu");
delay(2000);
currentState = digitalRead(9);
@ -174,8 +196,6 @@ void setup() {
inConf();
}
countdown(3);
if (connectWIFI) {
WiFi.begin("airgradient", "cleanair");
int retries = 0;
@ -185,19 +205,19 @@ void setup() {
Serial.print(".");
}
if (retries > 14) {
Serial.println(F("WiFi connection FAILED"));
Serial.println(F("WiFi connection to SSID airgradient failed"));
if (connectWIFI) connectToWifi();
}
if (WiFi.status() == WL_CONNECTED) {
if (WiFi.SSID() == "airgradient") {
ledTest();
}
sendPing();
Serial.println(F("WiFi connected!"));
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
}
updateOLED2("Warming Up", "Serial Number:", String(getNormalizedMac()));
}
@ -211,6 +231,21 @@ void loop() {
sendToServer();
}
void ledTest() {
updateOLED2("LED Test", "running", ".....");
setRGBledColor('r');
delay(1000);
setRGBledColor('g');
delay(1000);
setRGBledColor('b');
delay(1000);
setRGBledColor('w');
delay(1000);
setRGBledColor('n');
delay(1000);
//LED Test
}
void updateTVOC() {
uint16_t error;
char errorMessage[256];
@ -248,8 +283,6 @@ if (error) {
Serial.println(String(TVOC));
}
}
}
@ -403,7 +436,6 @@ void updateOLED2(String ln1, String ln2, String ln3) {
} while (u8g2.nextPage());
}
void updateOLED3() {
char buf[9];
u8g2.firstPage();
@ -441,7 +473,6 @@ if (inF) {
// there might also be single digits, not considered, sprintf might actually support a leading space
}
u8g2.drawLine(1, 13, 128, 13);
u8g2.setFont(u8g2_font_t0_12_tf);
u8g2.drawUTF8(1, 27, "CO2");
@ -459,7 +490,6 @@ if (inF) {
u8g2.drawStr(48, 27, "PM2.5");
u8g2.setFont(u8g2_font_t0_22b_tf);
if (inUSAQI) {
if (pm25 >= 0) {
sprintf(buf, "%d", PM_TO_AQI_US(pm25));
@ -596,12 +626,12 @@ String getNormalizedMac() {
}
void setRGBledCO2color(int co2Value) {
if (co2Value < 800) setRGBledColor('g');
if (co2Value >= 300 && co2Value < 800) setRGBledColor('g');
if (co2Value >= 800 && co2Value < 1000) setRGBledColor('y');
if (co2Value >= 1000 && co2Value < 1500) setRGBledColor('o');
if (co2Value >= 1500 && co2Value < 2000) setRGBledColor('r');
if (co2Value >= 2000 && co2Value < 3000) setRGBledColor('p');
if (co2Value >= 3000 && co2Value < 10000) setRGBledColor('b');
if (co2Value >= 3000 && co2Value < 10000) setRGBledColor('z');
}
void setRGBledColor(char color) {
@ -636,6 +666,20 @@ void setRGBledColor(char color) {
pixels.show();
}
break;
case 'b':
for (int i = 0; i < 11; i++) {
pixels.setPixelColor(i, pixels.Color(0, 0, 255));
delay(100);
pixels.show();
}
break;
case 'w':
for (int i = 0; i < 11; i++) {
pixels.setPixelColor(i, pixels.Color(255, 255, 255));
delay(100);
pixels.show();
}
break;
case 'p':
for (int i = 0; i < 11; i++) {
pixels.setPixelColor(i, pixels.Color(153, 0, 153));
@ -643,13 +687,20 @@ void setRGBledColor(char color) {
pixels.show();
}
break;
case 'b':
case 'z':
for (int i = 0; i < 11; i++) {
pixels.setPixelColor(i, pixels.Color(102, 0, 0));
delay(100);
pixels.show();
}
break;
case 'n':
for (int i = 0; i < 11; i++) {
pixels.setPixelColor(i, pixels.Color(0, 0, 0));
delay(100);
pixels.show();
}
break;
default:
// if nothing else matches, do the default
// default is optional

View File

@ -1,5 +1,5 @@
name=AirGradient Air Quality Sensor
version=2.4.10
version=2.4.11
author=AirGradient <support@airgradient.com>
maintainer=AirGradient <support@airgradient.com>
sentence=ESP8266 library for an air quality sensor featuring PM2.5, CO2, Temperature, TVOC and Humidity with OLED display.