Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: EthernetInterface ThingCloud mbed-rtos mbed
Diff: main.cpp
- Revision:
- 1:77bd7a299174
- Parent:
- 0:5daa2467c994
- Child:
- 2:88dce59f9a99
--- a/main.cpp Fri Jun 02 17:49:00 2017 +0000
+++ b/main.cpp Sat Jun 03 17:52:26 2017 +0000
@@ -24,7 +24,8 @@
uint16_t pm10, pm25;
int stack;
-float approxRollingAverage (float avg, float new_sample) {
+float approxRollingAverage (float avg, float new_sample)
+{
avg -= avg / N;
avg += new_sample / N;
return avg;
@@ -36,36 +37,48 @@
Channel.AddFloat(PM25/stack);
Channel.AddFloat(0);
Channel.AddFloat(0);
- stack=0; PM10=0; PM25=0;
+ stack=0;
+ PM10=0;
+ PM25=0;
if (Channel.SendData(thingSpeakKey)) pc.printf("Upload Error \r");
else pc.printf("Upload OK \r");
}
-int ReadNova(){
-int res=0;
- if (nova.readable()) {
- inbuff[pInbuff]=nova.getc();
- if (inbuff[pInbuff]==0xAA) {
- pInbuff=-1;
- }
- if (inbuff[pInbuff]==0xAB) {
- pm25=(inbuff[2]<<8)+inbuff[1];
- pm10=(inbuff[4]<<8)+inbuff[3];
- PM10+=pm10/10.0;
- PM25+=pm25/10.0;
- stack++;
- pc.printf("PM10=%.1f PM2.5=%.1f Stack=%d \r",pm10/10.0,pm25/10.0,stack);
- pInbuff=-1;
- res=1;
- }
- pInbuff++;
- }
- return res;
+int ReadNova()
+{
+ int res=0;
+ uint16_t old_pm10, old_pm25;
+ if (nova.readable()) {
+ inbuff[pInbuff]=nova.getc();
+ if (inbuff[pInbuff]==0xAA) {
+ pInbuff=-1;
+ }
+ if (inbuff[pInbuff]==0xAB) {
+ if (old_pm10!=0) old_pm10=pm10;
+ else old_pm10=5000;
+ if (old_pm25!=0) old_pm25=pm25;
+ else old_pm25=5000;
+
+ pm25=(inbuff[2]<<8)+inbuff[1];
+ pm10=(inbuff[4]<<8)+inbuff[3];
+ if ((pm25<(2*old_pm25)) && (pm10<(2*old_pm10))) { //Spike fra sortering
+ PM10+=pm10/10.0;
+ PM25+=pm25/10.0;
+ stack++;
+ pc.printf("PM10=%.1f PM2.5=%.1f Stack=%d \r",pm10/10.0,pm25/10.0,stack);
+ res=1;
+ }
+ pInbuff=-1;
+ }
+ pInbuff++;
+ }
+ return res;
}
DigitalOut myled(LED1);
-int main() {
+int main()
+{
pInbuff=0;
stack=0;
pc.printf("\n\r---------------------------------------------------------------\n\r");
@@ -73,7 +86,7 @@
eth.connect();
pc.printf("IP Address is %s\n\r", eth.getIPAddress());
while (true) {
- ReadNova();
+ ReadNova();
if (stack>=60) {
LogData();
}