rpanfili / airQualityMeter

Detects air particulate matter (PM - pm1, pm2.5, pm10) concentrations and sends data to an MQTT server. An alternative firmware for ESP8266 devices like the NodeMCU board written for Arduino IDE and PlatformIO
GNU General Public License v3.0
19 stars 5 forks source link

Support needed.... #5

Closed sirfalo closed 5 years ago

sirfalo commented 5 years ago

Hi

I tried to understand a bit manual which is related to your work (PMS5003ST).

It's first time when installed Visual Studio and nodemcu :) I was able to upload project to module and it connected to my wifi (changed config.json). However, I can't later go to local adress via browser... (it has local IP which I can ping, but can't get inside...). Any ideas what I can do wrong??

rpanfili commented 5 years ago

Hi Sirfalo, nice to hear you got this working! In this project there are no http endpoints configured apart the captive portal to setup connectivity. If you used the config.json file you are already good to go: specify the mqtt parameters and the nodemcu will stream data on the specified topic! If you want to debug you can listen to published messages with something like this:

mosquitto_sub -h {mqtt_server} -t "{mqtt_topic}" -u {mqtt_username} -P {mqtt_password} -v -i mosquitto_client

Let me know if you need further support!

sirfalo commented 5 years ago

Hi

Thank you for answer! Actually I'm positively surprised you answered, especially so fast :)

So, what I did. I set in config.json topic: "air_quality_meter/status" I can ping as before, but nothing comes to mqtt. I subscribed to MQTT via MQTTLens and when I'm publishing some packet from HA to "air_quality_meter/status", then I can see it's comming, but nothing comes from NodeMCU...

Sensor connected to 5V (as in sensor manual), but NodeMCU works on 3V so all should work...

Maybe sensor is dead?

sirfalo commented 5 years ago

I connected with termite and sensor sends such info.

BM[00]$[00] [00][10][00][10][00] [00][10][00][10][08][04][02]/[00]S[00][06][00][00][00][00][00][0F][00]Ü[02]B[00][00]‘[00][03]]

So something is there.

Config: image

sirfalo commented 5 years ago

Maybe I'm doing something stupid? I'm editing config.json in visual studio code. Then SAVE Then BUILD and later UPLOAD. Interesting is that if I'm changing WiFi ssid, Node is connecting anyhow to same network as before...

rpanfili commented 5 years ago

Hi again :) To upload a config.json file you have to follow this paragraph expecially this:

or by using the IDE top menu: "PlatformIO" >> "Run other target..." >> "PIO Upload File System Image"

("Upload File System image" from vscode platformIO sidebar menu)

So maybe if you are doing "save" >> "build" >> "upload" you are uploading the source code, not the spiff filesystem (an unrelated task that will store persistent data between updates like for example this configurations, etc)

Anyway the best think you can do is to debug serial outputs (via usb) from the running device from vscode command palette PlatformIO: serial monitor

Screenshot 2019-07-16 at 10 58 22

than you will be able to understand if it is able to connect to wifi/mqtt server/etc

Let me know if you solved with this two advices!

sirfalo commented 5 years ago

HA! I don't know what is actually the difference :) I mean, when I'm using BUILD and UPLOAD it goes for sure to NodeMCU because data from config.json HAVE to be transfered (how node will connect to my wifi?). But I'm far from understanding this deeper so I wrote in terminal

pio run -t uploadfs

which started terminal and made (maaaybe) same thing as upload, but... it works now :)

THANK YOU!

Something weird however I can see in terminal and serial debug:

got 40 chars stream


Concentration Units (standard) PM 1.0: 12 PM 2.5: 16 PM 10: 18

Concentration Units (environmental) PM 1.0: 12 PM 2.5: 16 PM 10: 18

Particles > 0.3um / 0.1L air:2415 Particles > 0.5um / 0.1L air:668 Particles > 1.0um / 0.1L air:87 Particles > 2.5um / 0.1L air:6 Particles > 5.0um / 0.1L air:2 Particles > 10.0 um / 0.1L air:1

HCHO: 0.0140 Temperature: 20.80 Humidity: 58.10

[1] skip char 0x0 [1] skip char 0x0 found start char [2] next char is not SIG2, skip (0x42) found start char [2] next char is not SIG2, skip (0x0) [1] skip char 0x0 [1] skip char 0xFF found start char [2] next char is not SIG2, skip (0xFF) [1] skip char 0xFF [1] skip char 0x0 [1] skip char 0x0 [1] skip char 0x0 [1] skip char 0x0 found start char [2] next char is not SIG2, skip (0x0) [1] skip char 0x0 [1] skip char 0x0 found start char [2] next char is not SIG2, skip (0xFF) [1] skip char 0xFF [1] skip char 0x0 [1] skip char 0x0 [1] skip char 0x0 found start char [2] next char is not SIG2, skip (0x0) [1] skip char 0x0 [1] skip char 0xFF [1] skip char 0x0 found start char found second char Framelen OK got 40 chars stream Checksum failure Sum: 1006 - check: 834 found start char [2] next char is not SIG2, skip (0xFF) [1] skip char 0xFF [1] skip char 0x0 found start char

BTW, where did you made this photo of you???

rpanfili commented 5 years ago

I'm happy to hear that is working :) The SPIFFS is actually the filesystem of these devices and usually refers to a memory portion which the firmware can interact with, create files, etc and it persists after following firmware flashes. In our case it's where it looks for/stores the config json file. The debug output is fine and it's pretty common that the pm sensor sends data with a wrong checksum message so the software flush them until it got a valid sequence. The picture was taken in Val D'Aosta, Italy :) Closing the issue!

sirfalo commented 5 years ago

I was somehow convinced that this was more somewhere in Scandinavia :)

Thank you for explanations, now I'm smarter thanks to you :)

One more question - is this possible to slow down serial communication between PMS and NodeMCU? I have lot of transmission errors - when PMS sends some results, then there is often checksum failure. Funny that I can see that Node sends new values after reboot, but it's not sending sometimes info for 1h...

rpanfili commented 5 years ago

The serial communication between nodemcu and PMS sensor is already set at the reference baud rate:

https://github.com/rpanfili/airQualityMeter/blob/eac6c8b352ea34d400d5c825c46cf1271ad860c7/src/main.cpp#L430

https://github.com/Arduinolibrary/DFRobot_SEN0233_Air_Quality_Monitor/blob/master/PMS5003ST%20series%20data%20manua_English_V2.6%20.pdf see appendix I

What is strange is that no data are sent for a long period. Did you debug those situations? The device was unable to get a valid checksum or no data are available on serial?

At the moment I'm unable to test this source code since I'm working on a software for a bit more complex scenario where I rewrote the retrieval/checksum code portion. If you had some spare time and want to collaborate I can push a branch but maybe it will need some minor changes...

sirfalo commented 5 years ago

Well, it's actually sending always something. Sensor I understand sends results every few minutes and in debug I can see that instead of some values there is checksum error. It later results is such effect. image

I already shortened cable and separated them to not be super close...

sirfalo commented 5 years ago

Here is what is happening right after start:

0000001.061: Setup device
mounting FS..
0000001.085: filesystem mounted
0000001.086: Opened config file
0000001.087: json loaded
{"wifi_ssid":"SynologySmartConnect","wifi_password":"xxxx","access_point_prefix":"AQM-","access_point_password":"stop_air_pollution","mqtt_server":"192.168.1.150","mqtt_port":"1883","mqtt_username":"HA","mqtt_password":"xxxx","mqtt_topic":"air_quality_meter/status","ota_password":"","ota_port":""}0000001.113: Trying to connect to WiFi network
*WM: Adding parameter
*WM: access_point_prefix
*WM: Adding parameter
*WM: access_point_password
*WM: Adding parameter
*WM: mqtt_server
*WM: Adding parameter
*WM: mqtt_port
*WM: Adding parameter
*WM: mqtt_username
*WM: Adding parameter
*WM: mqtt_password
*WM: Adding parameter
*WM: mqtt_topic
*WM: Adding parameter
*WM: ota_password
*WM: Adding parameter
*WM: ota_port
*WM:
*WM: AutoConnect
*WM: Connecting as wifi client...
*WM: Using last saved values, should be faster
*WM: Connection result:
*WM: 3
*WM: IP Address:
*WM: 192.168.1.229
0000009.150: Connected
0000009.151: mqtt server: 192.168.1.150 - port: 1883
username : 'HA' - pass: 'falownia04!$'
Attempting MQTT connection...connected
found start char
found second char
Framelen OK
got 40 chars stream

---------------------------------------
Concentration Units (standard)
PM 1.0: 42              PM 2.5: 48              PM 10: 56
---------------------------------------
Concentration Units (environmental)
PM 1.0: 40              PM 2.5: 48              PM 10: 56
---------------------------------------
Particles > 0.3um / 0.1L air:0
Particles > 0.5um / 0.1L air:0
Particles > 1.0um / 0.1L air:0
Particles > 2.5um / 0.1L air:0
Particles > 5.0um / 0.1L air:0
Particles > 10.0 um / 0.1L air:0
---------------------------------------
HCHO: 0.0050
Temperature: 21.00
Humidity: 54.80
---------------------------------------
found start char
found second char
Framelen OK
got 40 chars stream
Checksum failure
Sum: 970 - check: 48
[1] skip char 0x1A
[1] skip char 0x49
[1] skip char 0x7
[1] skip char 0x3D
[1] skip char 0x0
[1] skip char 0xF6
[1] skip char 0x0
[1] skip char 0xF
[1] skip char 0x0
[1] skip char 0x2
[1] skip char 0x0
[1] skip char 0x1
[1] skip char 0x0
[1] skip char 0x2
[1] skip char 0x0
[1] skip char 0xD2
[1] skip char 0x2
[1] skip char 0x25
[1] skip char 0x0
[1] skip char 0x0
[1] skip char 0x91
[1] skip char 0x0
[1] skip char 0x4
found start char
found second char
Framelen OK
got 40 chars stream

---------------------------------------
Concentration Units (standard)
PM 1.0: 36              PM 2.5: 48              PM 10: 52
---------------------------------------
Concentration Units (environmental)
PM 1.0: 28              PM 2.5: 40              PM 10: 49
---------------------------------------
Particles > 0.3um / 0.1L air:6897
Particles > 0.5um / 0.1L air:1886
Particles > 1.0um / 0.1L air:235
Particles > 2.5um / 0.1L air:16
Particles > 5.0um / 0.1L air:4
Particles > 10.0 um / 0.1L air:2
---------------------------------------
HCHO: 0.0010
Temperature: 21.00
Humidity: 54.80
---------------------------------------
[1] skip char 0x0
[1] skip char 0xFF
found start char
[2] next char is not SIG2, skip (0x42)
found start char
[2] next char is not SIG2, skip (0x42)
found start char
[2] next char is not SIG2, skip (0x42)
found start char
[2] next char is not SIG2, skip (0x0)
[1] skip char 0x0
[1] skip char 0x0
[1] skip char 0xE4
found start char
[2] next char is not SIG2, skip (0x0)
[1] skip char 0x0
found start char
[2] next char is not SIG2, skip (0x0)
[1] skip char 0x0
found start char
[2] next char is not SIG2, skip (0x42)
found start char
[2] next char is not SIG2, skip (0x0)
[1] skip char 0x0
[1] skip char 0x0
[1] skip char 0x13
found start char
[2] next char is not SIG2, skip (0x42)
found start char
[2] next char is not SIG2, skip (0x2F)
[1] skip char 0x2F
found start char
[2] next char is not SIG2, skip (0x0)
[1] skip char 0x0
[1] skip char 0x5F
[1] skip char 0xB
[1] skip char 0xE0
[1] skip char 0x0
[1] skip char 0xA
[1] skip char 0x0
[1] skip char 0x0
[1] skip char 0x0
[1] skip char 0x0
[1] skip char 0x0
[1] skip char 0x0
[1] skip char 0x0
[1] skip char 0xD4
[1] skip char 0x2
[1] skip char 0x1D
[1] skip char 0x0
[1] skip char 0x0
[1] skip char 0x91
[1] skip char 0x0
[1] skip char 0x5
[1] skip char 0x3
found start char
found second char
Framelen OK
got 40 chars stream
Checksum failure
Sum: 2181 - check: 65346
found start char
[2] next char is not SIG2, skip (0x0)
[1] skip char 0x0
found start char
[2] next char is not SIG2, skip (0x42)
found start char
[2] next char is not SIG2, skip (0x0)
[1] skip char 0x0
found start char
[2] next char is not SIG2, skip (0x42)
found start char
[2] next char is not SIG2, skip (0x42)
found start char
[2] next char is not SIG2, skip (0xFF)
[1] skip char 0xFF
found start char
[2] next char is not SIG2, skip (0xFF)
[1] skip char 0xFF
[1] skip char 0x0
[1] skip char 0x0
found start char
[2] next char is not SIG2, skip (0x42)
found start char
[2] next char is not SIG2, skip (0x0)
[1] skip char 0x0
found start char
[2] next char is not SIG2, skip (0x42)
found start char
[2] next char is not SIG2, skip (0x24)
[1] skip char 0x24
[1] skip char 0x43
rpanfili commented 5 years ago

Well, it's actually sending always something. Sensor I understand sends results every few minutes and in debug I can see that instead of some values there is checksum error. It later results is such effect. image

I already shortened cable and separated them to not be super close...

@sirfalo this is not an expected behavior so I opened another issue about this. I'll try to adapt the routine I'm using to read data on an updated project as soon as possible so we can check if it will solve or not! Stay tuned :)