Permalink
Browse files

Add photon station

  • Loading branch information...
evanxd committed Mar 29, 2016
1 parent 31716fe commit c38b3594af2fa836e1e725123a25b596840dc069
Showing with 50 additions and 0 deletions.
  1. +50 −0 photon-station.ino
View
@@ -0,0 +1,50 @@
long pm10 = 0;
long pm25 = 0;
long pm100 = 0;
void setup() {
Serial.begin(9600);
Serial1.begin(9600);
}
void loop() {
int index = 0;
char value;
char previousValue;
while (Serial1.available()) {
value = Serial1.read();
if ((index == 0 && value != 0x42) || (index == 1 && value != 0x4d)){
Serial.println("Cannot find the data header.");
break;
}
if (index == 4 || index == 6 || index == 8 || index == 10 || index == 12 || index == 14) {
previousValue = value;
}
else if (index == 5){
pm10 = 256 * previousValue + value;
Serial.print("{ ");
Serial.print("\"pm10\": ");
Serial.print(pm10);
Serial.print(", ");
}
else if (index == 7){
pm25 = 256 * previousValue + value;
Serial.print("\"pm25\": ");
Serial.print(pm25);
Serial.print(", ");
}
else if (index == 9){
pm100 = 256 * previousValue + value;
Serial.print("\"pm100\": ");
Serial.print(pm100);
} else if (index > 15) {
break;
}
index++;
}
while(Serial1.available()) Serial1.read();
Serial.println(" }");
delay(1000);
}

0 comments on commit c38b359

Please sign in to comment.