Dust Sesnsor PMS5003

Dependencies:   DustSenzor NetServices ThingSpeakEthernet mbed

Fork of PMS5003 by marko puric

Files at this revision

API Documentation at this revision

Comitter:
mpuric
Date:
Mon Jun 05 08:12:57 2017 +0000
Parent:
8:9b35ac104ab7
Child:
10:5ff1bf492439
Commit message:
Init commit

Changed in this revision

C12832.lib Show diff for this revision Revisions of this file
DustSenzor.lib Show annotated file Show diff for this revision Revisions of this file
I2CR.lib Show diff for this revision Revisions of this file
INA219.lib Show diff for this revision Revisions of this file
Sensor.cpp Show diff for this revision Revisions of this file
Sensor.h Show diff for this revision Revisions of this file
TextLCD.lib Show annotated file Show diff for this revision Revisions of this file
ThingSpeak.cpp Show diff for this revision Revisions of this file
ThingSpeak.h Show diff for this revision Revisions of this file
ThingSpeak/ThingSpeak.cpp Show annotated file Show diff for this revision Revisions of this file
ThingSpeak/ThingSpeak.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/C12832.lib	Sun Nov 29 14:26:32 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://developer.mbed.org/users/chris/code/C12832/#7de323fa46fe
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DustSenzor.lib	Mon Jun 05 08:12:57 2017 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/mpuric/code/DustSenzor/#fd42a3f8c7eb
--- a/I2CR.lib	Sun Nov 29 14:26:32 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/ShockSoc/code/I2CR/#375ecd0ed73d
--- a/INA219.lib	Sun Nov 29 14:26:32 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-https://developer.mbed.org/users/tsoic/code/INA219/#6b9f92e99dd7
--- a/Sensor.cpp	Sun Nov 29 14:26:32 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,14 +0,0 @@
-#include "Sensor.h"
-#include "mbed.h"
-
-Sensor::Sensor(PinName sensorPin, float Koef) : sensorInput(sensorPin), K(Koef) { 
-
-} 
-
-float Sensor::read() {
-        readVal[0] = sensorInput;
-        realVal = readVal[0]; //* Računanje srednje vrijednosti
-        return realVal  *= K;
-         
-}
-
--- a/Sensor.h	Sun Nov 29 14:26:32 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,41 +0,0 @@
-#ifndef _SENSOR_H
-#define SENSOR_H  
-#include "mbed.h"
-
-/** Simple class for sensor with linear otuput. Made for later upgrading, to avarage values from ADC
- * Example:
- * @code
- * #include "mbed.h"
- * #include "Sensor.h"
- * #include "INA219_reg.h"
- *
- * Sensor voltageDivider(p20,5);
- * float value;
- *
- * int main() {
- *     value = voltageDivider.read();
- * }
- * @endcode
-
-*/
-class Sensor {
-     
-     public:
-    /**
-     * @param: PinName of ADC to which sensor is connected
-     *        float value for multiplifing with raw value from ADC to get real value
-    */    
-    Sensor(PinName, float);    
-    /** Read real messured value
-     * return: float real messured value 
-     *
-    **/                               
-        float read();                                   
-                                       
-     private:
-     
-        AnalogIn sensorInput;           
-        float readVal[], realVal, K;
-};
-
-#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD.lib	Mon Jun 05 08:12:57 2017 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/mpuric/code/TextLCD/#29f59aab1561
--- a/ThingSpeak.cpp	Sun Nov 29 14:26:32 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,48 +0,0 @@
-#include "mbed.h"
-#include "EthernetNetIf.h"
-#include "HTTPClient.h"
-#include "ThingSpeak.h"
-
-Serial pc(USBTX, USBRX);
-
-ThingSpeak::ThingSpeak(char* Key) : thingSpeakKey(Key) {      
-    thingSpeakUrl = "https://api.thingspeak.com/update";
-    urlBuffer[0] = 0;
-    fieldBuffer[0] = 0;
-}
-
-void ThingSpeak::connect() {
-    pc.printf("Setting up Ethernet...\r\n");
-    EthernetErr ethErr = eth.setup();
-    if(ethErr){
-        pc.printf("Error %d in ethernet setup.\r\n", ethErr);  
-        connect();
-        }
-    pc.printf("Ethernet setup OK\r\n");
-}
-/*
-void ThingSpeak::getIP() {
-   
-}
-*/
-void ThingSpeak::setField(float field, int i) {
-    char fieldi;
-    char fieldShortBuff[8];
-    sprintf(fieldShortBuff, "%f", field);
-    sprintf(&fieldi, "%i", i);
-    strncat(fieldBuffer, "&field", 6 );
-    strncat(fieldBuffer, &fieldi , 1);
-    strncat(fieldBuffer, "=", 1);
-    strncat(fieldBuffer, fieldShortBuff , 4);    
-}
-
-void ThingSpeak::putUp() {
-    sprintf(urlBuffer, "%s?key=%s%s", thingSpeakUrl, thingSpeakKey, fieldBuffer);
-    pc.printf("URL Buffer request: %s ", urlBuffer); 
-    res = http.get(urlBuffer, &resp);
-    if (res == HTTP_OK)
-        pc.printf(" Result :\"%s\"\r\n", resp.gets());
-    else
-        pc.printf(" Error %d\r\n", res); 
-    fieldBuffer[0] = 0;         
-}
\ No newline at end of file
--- a/ThingSpeak.h	Sun Nov 29 14:26:32 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,71 +0,0 @@
-#ifndef THINGSPEAK_H
-#define THINGSPEAK_H
-#define HOSTNAME "mbed"
-#include "mbed.h"
-#include "EthernetNetIf.h"
-#include "HTTPClient.h"
-
-/** Class for sending data to ThingSpeak over ethernet,
- *  Class is using old mbed library revision and EthernetNetIf from
- *  https://developer.mbed.org/users/okini3939/notebook/TCPSocket_jp/
- * Example:
- * @code
- * #include "mbed.h"
- * #include "ThingSpeak.h"
- *
- * ThingSpeak thingSpeak("XXXXXXXXXXXXXXXX");
- *
- * int main() {
- *     int i = 1;
- *     flot value = 3.14;
- *     thingSpeak.connect();
- *     thingSpeak.setField(value,i)
- *     thingSpeak.putUp();
- * }
- * @endcode
-*/
-class ThingSpeak
-{
-
-public:
-    /**
-     * @param: write api key provided from ThingSpeak chanell
-    */
-    ThingSpeak(char*);
-    /**
-     * Establishing ethernet connection until connected
-     *
-    */
-    void connect();
-    /**
-     * Should be added
-    */
-    /**
-    *        void getIP();
-    */
-    /**
-     * Put up data to thing speak when all fields are set
-    */
-    void putUp();
-    /**
-     *Setting values to the field, they should be set in order.
-     * It's not required to set them all  (example: you can set 1, 2, 3 or 1, 3)
-     * @param field value to store on
-     * @param i number of a field
-    */
-    void setField(float field, int i);
-private:
-
-    char* thingSpeakUrl;
-    char* thingSpeakKey;
-    char urlBuffer[511];
-    char fieldBuffer[255];
-    EthernetNetIf eth;
-    EthernetErr ethErr;
-    HTTPClient http;
-    IpAddr ethIp;
-    HTTPText resp;
-    HTTPResult res;
-};
-
-#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ThingSpeak/ThingSpeak.cpp	Mon Jun 05 08:12:57 2017 +0000
@@ -0,0 +1,62 @@
+#include "mbed.h"
+#include "EthernetNetIf.h"
+#include "HTTPClient.h"
+#include "ThingSpeak.h"
+
+Serial pc(USBTX, USBRX);
+
+ThingSpeak::ThingSpeak(char* Key) : thingSpeakKey(Key) {      
+    thingSpeakUrl = "https://api.thingspeak.com/update";
+    thingSpeakRead = "https://api.thingspeak.com/channels/";
+    urlBuffer[0] = 0;
+    fieldBuffer[0] = 0;
+}
+ float ThingSpeak::pull(long int readKey, int field) {
+    sprintf(urlBuffer, "%s%d/fields/%d/last", thingSpeakRead, readKey, field ); 
+    pc.printf("URL Buffer request: %s ", urlBuffer); 
+    res = http.get(urlBuffer, &resp);
+    if (res == HTTP_OK){
+        pc.printf(" Result :\"%s\"\r\n,", resp.gets(), res);
+        float resp2 = atoi(resp.gets());
+        return resp2;
+        }
+    else {
+        pc.printf(" Error %d\r\n", res); 
+        return false;
+    }      
+}
+void ThingSpeak::connect() {
+    pc.printf("Setting up Ethernet...\r\n");
+    EthernetErr ethErr = eth.setup();
+    if(ethErr){
+        pc.printf("Error %d in ethernet setup.\r\n", ethErr);  
+        connect();
+        }
+    pc.printf("Ethernet setup OK\r\n");
+}
+/*
+void ThingSpeak::getIP() {
+   
+}
+*/
+void ThingSpeak::setField(float field, int i) {
+    char fieldi;
+    char fieldShortBuff[8];
+    sprintf(fieldShortBuff, "%f", field);
+    sprintf(&fieldi, "%i", i);
+    strncat(fieldBuffer, "&field", 6 );
+    strncat(fieldBuffer, &fieldi , 1);
+    strncat(fieldBuffer, "=", 1);
+    strncat(fieldBuffer, fieldShortBuff , 6);    
+}
+
+void ThingSpeak::putUp() {
+    sprintf(urlBuffer, "%s?key=%s%s", thingSpeakUrl, thingSpeakKey, fieldBuffer);
+    pc.printf("URL Buffer request: %s ", urlBuffer); 
+    res = http.get(urlBuffer, &resp);
+    if (res == HTTP_OK)
+        pc.printf(" Result :\"%s\"\r\n", resp.gets());
+    else
+        pc.printf(" Error %d\r\n", res); 
+    fieldBuffer[0] = 0;         
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ThingSpeak/ThingSpeak.h	Mon Jun 05 08:12:57 2017 +0000
@@ -0,0 +1,75 @@
+#ifndef THINGSPEAK_H
+#define THINGSPEAK_H
+#define HOSTNAME "mbed"
+#include "mbed.h"
+#include "EthernetNetIf.h"
+#include "HTTPClient.h"
+
+/** Class for sending data to ThingSpeak over ethernet,
+ *  Class is using old mbed library revision and EthernetNetIf from
+ *  https://developer.mbed.org/users/okini3939/notebook/TCPSocket_jp/
+ * Example:
+ * @code
+ * #include "mbed.h"
+ * #include "ThingSpeak.h"
+ *
+ * ThingSpeak thingSpeak("XXXXXXXXXXXXXXXX");
+ *
+ * int main() {
+ *     int i = 1;
+ *     flot value = 3.14;
+ *     thingSpeak.connect();
+ *     thingSpeak.setField(value,i)
+ *     thingSpeak.putUp();
+ * }
+ * @endcode
+*/
+class ThingSpeak
+{
+
+public:
+    /**
+     * @param: write api key provided from ThingSpeak chanell
+    */
+    ThingSpeak(char*);
+    /**
+     * Establishing ethernet connection until connected
+     *
+    */
+    void connect();
+    
+    float pull(long int, int);
+    
+    /**
+     * Should be added
+    */
+    /**
+    *        void getIP();
+    */
+    /**
+     * Put up data to thing speak when all fields are set
+    */
+    void putUp();
+    /**
+     *Setting values to the field, they should be set in order.
+     * It's not required to set them all  (example: you can set 1, 2, 3 or 1, 3)
+     * @param field value to store on
+     * @param i number of a field
+    */
+    void setField(float field, int i);
+private:
+
+    char* thingSpeakUrl;
+    char* thingSpeakRead;
+    char* thingSpeakKey;
+    char urlBuffer[1023];
+    char fieldBuffer[1023];
+    EthernetNetIf eth;
+    EthernetErr ethErr;
+    HTTPClient http;
+    IpAddr ethIp;
+    HTTPText resp;
+    HTTPResult res;
+};
+
+#endif
\ No newline at end of file
--- a/main.cpp	Sun Nov 29 14:26:32 2015 +0000
+++ b/main.cpp	Mon Jun 05 08:12:57 2017 +0000
@@ -1,53 +1,49 @@
 #include "mbed.h"
-#include "iostream"
 #include "ThingSpeak.h"
-#include "Sensor.h"
-#include "C12832.h"
-#include "INA219.h"
+#include "TextLCD.h"
+#include "DustSenzor.h"
+
 
 
 
-    ThingSpeak ts("074MPWFODR7JHD1K"); 
-    C12832 lcd(p5, p7, p6, p8, p11);
-    Sensor current(p19,4.65);
-    Sensor voltage(p20,16.23);
-   
-
+ThingSpeak ts("FI2NZGSOB8LSR8YX"); 
+DustSenzor ds(p5, p9, p10);
 
 int main() {
-    INA219 ina219;
-    float U, I, ina[3];
-    int i;
-    
-    lcd.cls();
-    lcd.locate(0,3);  
-    lcd.printf("Ethernet Connecting ! \n");  
-    ts.connect();
-    lcd.printf("Ethernet Connected ! \n");
-    wait(1);
+    ds.stop();
+    float *ptr;
     
-    while(1){
-                  
-        U = voltage.read();       
-        I = current.read();
-        ina[0] = ina219.readRawReg(0x04);//* Current *//
-        ina[1] = ina219.readRawReg(0x02); //* Bus Voltage *//
-        ina[2] = ina219.readRawReg(0x03);//* Power *// 
-    
-        lcd.cls();
-        lcd.locate(0,3);    
-        lcd.printf("V = %.2f V \n",ina[1]);
-        lcd.printf("I = %.2f A \n",ina[0]);
-        lcd.printf("P = %.2f W \n",ina[2]);
+    ts.connect();
+    wait(1);
+    while(1){     
+        float res = ts.pull(282724, 1);
+        if(res == 1){
+            ds.start();
+            }
+        while( res == 1){
+                ptr = ds.read();
+                for( int i = 0; i < 6; i++) {
+                    ts.setField(*(ptr + i), i+1);
+                }
+                ts.putUp();
+                wait(15);
+                res = ts.pull(282724, 1);
+            }
+            ds.stop();           
+    }
+}
         
-        i = 1;
-        ts.setField(U, i++);
-        ts.setField(I, i++); 
-        ts.setField(I*U, i++); 
-        for(int j = 0 ; j<= 2; j++)
-            ts.setField(ina[j], i++);
-            
-        ts.putUp();
-        wait(15);                    
-    }
-}
\ No newline at end of file
+
+
+/* void DustSenzor::modeSet(){
+    if(debounce.read_ms() > 250 && provjera==false) {
+        set=1;
+        debounce.reset();
+        provjera=true;
+        } 
+        else if(debounce.read_ms() > 250 && provjera==true){
+                set=0;
+                debounce.reset();
+                provjera=false;
+        }
+    } */
\ No newline at end of file