Dust Sesnsor PMS5003

Dependencies:   NetServices ThingSpeakEthernet mbed

Files at this revision

API Documentation at this revision

Comitter:
mpuric
Date:
Mon Jun 05 08:17:46 2017 +0000
Parent:
9:07f9279c30f7
Child:
11:8e2829f54314
Commit message:
ThinsSpeak converted to library

Changed in this revision

ThingSpeak.lib Show annotated file Show diff for this revision Revisions of this file
ThingSpeak/ThingSpeak.cpp Show diff for this revision Revisions of this file
ThingSpeak/ThingSpeak.h Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ThingSpeak.lib	Mon Jun 05 08:17:46 2017 +0000
@@ -0,0 +1,1 @@
+ThingSpeak#a7bce9e88175
--- a/ThingSpeak/ThingSpeak.cpp	Mon Jun 05 08:12:57 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,62 +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";
-    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
--- a/ThingSpeak/ThingSpeak.h	Mon Jun 05 08:12:57 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,75 +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();
-    
-    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