Skip to content

Commit 3519603

Browse files
committed
La manera desfasada de leer los datos hacía muy improbable encontrar datos validos para decodificar una trama, en una ventana de tiempo se espera el caracter que indica el comienzo de la trama
1 parent 42bdf7c commit 3519603

File tree

4 files changed

+48
-42
lines changed

4 files changed

+48
-42
lines changed

sensor-laser/src/gps.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ GPSData parseGPSData() {
9292
}
9393

9494
GPSData getGPSData() {
95-
readGPS(5000);
95+
readGPS(800);
9696
GPSData data = parseGPSData();
9797
return data;
9898
}

sensor-laser/src/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ void setup() {
9898

9999
void loop() {
100100
gps = getGPSData();
101-
if(gps.ready) {
102-
dht11 = getDHT11Data();
101+
if(gps.ready) {
102+
dht11 = getDHT11Data();
103103
plantower = getPlantowerData();
104104

105105
if(plantower.ready) {
@@ -110,7 +110,7 @@ void loop() {
110110
if(plantowerData.ready) {
111111
ledParticulateQuality(plantowerData);
112112
}
113-
}
113+
}
114114

115115
drd.loop();
116116
}

sensor-laser/src/plantower.cpp

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -47,48 +47,54 @@ int parsePM10(unsigned char *thebuf) {
4747
return PM10Val;
4848
}
4949

50-
PlantowerData readPlantower() {
51-
PlantowerData data;
52-
53-
if(pmsSerial.find(0x42)) { //start to read when detect 0x42
54-
Serial.println("has 0x42");
5550

56-
pmsSerial.readBytes(buf,LENG);
57-
58-
if(buf[0] == 0x4d){
59-
Serial.println("has 0x4d");
60-
if(checkValue(buf,LENG)){
61-
Serial.println("value checked");
62-
PM01Value = parsePM01(buf); //count PM1.0 value of the air detector module
63-
PM2_5Value = parsePM2_5(buf);//count PM2.5 value of the air detector module
64-
PM10Value = parsePM10(buf); //count PM10 value of the air detector module
51+
PlantowerData readPlantower(unsigned long ms) {
52+
PlantowerData data;
6553

66-
data.ready = 1;
67-
data.pm1 = PM01Value;
68-
data.pm10 = PM10Value;
69-
data.pm25 = PM2_5Value;
54+
unsigned long start = millis();
55+
wdt_disable();
56+
57+
do {
58+
Serial.print("Timestamp: ");
59+
Serial.println(millis() - start);
60+
//while(pmsSerial.available()) {
61+
if(pmsSerial.find(0x42)) { //start to read when detect 0x42
62+
Serial.println("has 0x42");
63+
64+
pmsSerial.readBytes(buf,LENG);
65+
66+
if(buf[0] == 0x4d){
67+
Serial.println("has 0x4d");
68+
if(checkValue(buf,LENG)){
69+
Serial.println("value checked");
70+
PM01Value = parsePM01(buf); //count PM1.0 value of the air detector module
71+
PM2_5Value = parsePM2_5(buf);//count PM2.5 value of the air detector module
72+
PM10Value = parsePM10(buf); //count PM10 value of the air detector module
73+
74+
data.ready = 1;
75+
data.pm1 = PM01Value;
76+
data.pm10 = PM10Value;
77+
data.pm25 = PM2_5Value;
78+
}
79+
}
7080
}
71-
}
72-
}
73-
74-
static unsigned long OledTimer = millis();
81+
// }
82+
} while (millis() - start < ms);
7583

76-
if(millis() - OledTimer >= 5000) {
77-
OledTimer = millis();
84+
wdt_enable(1000);
7885

79-
Serial.print("PM1.0: ");
80-
Serial.print(PM01Value);
81-
Serial.println(" ug/m3");
86+
Serial.print("PM1.0: ");
87+
Serial.print(PM01Value);
88+
Serial.println(" ug/m3");
8289

83-
Serial.print("PM2.5: ");
84-
Serial.print(PM2_5Value);
85-
Serial.println(" ug/m3");
90+
Serial.print("PM2.5: ");
91+
Serial.print(PM2_5Value);
92+
Serial.println(" ug/m3");
8693

87-
Serial.print("PM1 0: ");
88-
Serial.print(PM10Value);
89-
Serial.println(" ug/m3");
90-
Serial.println();
91-
}
94+
Serial.print("PM1 0: ");
95+
Serial.print(PM10Value);
96+
Serial.println(" ug/m3");
97+
Serial.println();
9298

9399
return data;
94100
}
@@ -100,6 +106,6 @@ void setupPlantower() {
100106
}
101107

102108
PlantowerData getPlantowerData() {
103-
PlantowerData data = readPlantower();
109+
PlantowerData data = readPlantower(1000);
104110
return data;
105111
}

sensor-laser/src/wifi.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ void setupWifi() {
1818
// respond to GET requests on URL /heap
1919
server.on("/log", HTTP_GET, [](AsyncWebServerRequest *request){
2020
//Download index.htm
21-
request->_tempFile = SPIFFS.open("datalog.txt", "r");
21+
request->_tempFile = SPIFFS.open("log", "r");
2222
request->send(request->_tempFile, request->_tempFile.name(), String(), true);
2323
//AsyncWebServerResponse *response = request->beginResponse(SPIFFS, "log", String(), true);
2424
});
@@ -29,7 +29,7 @@ void setupWifi() {
2929
// respond to GET requests on URL /heap
3030
AsyncWiFiManager wifiManager(&server,&dns);
3131
//reset settings - for testing
32-
//wifiManager.resetSettings();
32+
wifiManager.resetSettings();
3333

3434
//set callback that gets called when connecting to previous WiFi fails, and enters Access Point mode
3535
wifiManager.setAPCallback(configModeCallback);

0 commit comments

Comments
 (0)