Hello guys… Im trying to setup with Dust Sensor with PMS7003 and Wemos D1 Mini…
But i got a so many error and i dont know this coding is right or not... I alreday made PMS7003 sensor + crystalLCD... it
s Work properly…
but i try to made with wemos d1… it`s to complicated…
Somebody help me…
here is my massy coding…
include "ESP8266WiFi.h"
include "SoftwareSerial.h"
String apiKey="8BDO9VISRFNU9FJK";
const char* server="api.thingspeak.com";
const char* ssid="kwangsub_5g";
const char* password = "";
WiFiClient client;
unsigned long sleepTime= 300;
unsigned char chrRecv;
unsigned char chrData[30];
SoftwareSerial myPMS7003(1,2);
byte bytCount = 0;
void setup() {
define PM1_0_ATMOSPHERE_H 8
define PM1_0_ATMOSPHERE_L 9
define PM2_5_ATMOSPHERE_H 10
define PM2_5_ATMOSPHERE_L 11
define PM10_ATMOSPHERE_H 12
define PM10_ATMOSPHERE_L 13
define START_1 0x42
define START_2 0x4d
WiFi.begin(ssid,password);
ESP.deepSleep(sleepTime * 1000000);
}
void loop() {
if (myPMS7003.available())
{
chrRecv = myPMS7003.read();
if (chrRecv == START_1 && bytCount ==0) bytCount = 1;
if (chrRecv == START_2 && bytCount ==1) bytCount = 2;
if (bytCount == 2)
{
bytCount = 0;
for(int i = 0; i < 30; i++)
{
chrData[i] = myPMS7003.read();
}
ShowPM_ATMO(chrData);
delay(1000); //sleep 5 seconds
}
}
}
unsigned int GetPM_Data(unsigned char chrSrc[], byte bytHigh, byte bytLow)
{
return (chrSrc[bytHigh] << 8) + chrSrc[bytLow];
}
void ShowPM_ATMO(unsigned char chrData[])
{
if(client.connect(server,80)){
String postStr = apiKey;
postStr +="&field1=";
postStr +=String(GetPM_Data(chrData, PM2_5_ATMOSPHERE_H, PM2_5_ATMOSPHERE_L));
postStr +="&field2=";
postStr += String(GetPM_Data(chrData, PM10_ATMOSPHERE_H, PM10_ATMOSPHERE_L));
postStr += "\r\n\r\n";
client.print("POST /update HTTP/1.1\n");
}
client.stop();
}