Dust Sesnsor PMS5003
Dependencies: NetServices ThingSpeakEthernet mbed
Revision 7:1da0a084cd69, committed 2015-11-29
- Comitter:
- tsoic
- Date:
- Sun Nov 29 13:41:05 2015 +0000
- Parent:
- 6:ebbde59c5a1d
- Child:
- 8:9b35ac104ab7
- Commit message:
Changed in this revision
--- a/INA219.lib Fri Nov 20 08:28:11 2015 +0000 +++ b/INA219.lib Sun Nov 29 13:41:05 2015 +0000 @@ -1,1 +1,1 @@ -https://developer.mbed.org/users/tsoic/code/INA219/#cdfbda214bee +https://developer.mbed.org/users/tsoic/code/INA219/#6b9f92e99dd7
--- a/Sensor.cpp Fri Nov 20 08:28:11 2015 +0000
+++ b/Sensor.cpp Sun Nov 29 13:41:05 2015 +0000
@@ -2,19 +2,13 @@
#include "mbed.h"
Sensor::Sensor(PinName sensorPin, float Koef) : sensorInput(sensorPin), K(Koef) {
-//* Implementacija kontruktora kako bi spojio dani ulazni pin i koeficijent množenja sa privatnim varijablama klase Sensor
+
}
-void Sensor::read() {
- //* Očitvanje vrijednosti analognom ulaza 10 puta i spremanje vrijednosti u float polje readVal[]
- readVal[0] = sensorInput;
+float Sensor::read() {
+ readVal[0] = sensorInput;
+ realVal = readVal[0]; //* Računanje srednje vrijednosti
+ return realVal *= K;
}
-float Sensor::calc() {
- //* Potrebno je postaviti 0 u lokalnu varijablu sum 0kako se u njoj nebi pojavili neki neočekivani brojevi
-
- realVal = readVal[0]; //* Računanje srednje vrijednosti
- return realVal *= K; //* Vračanje stvarne vrijednosti za daljnu obradu
-}
-
--- a/Sensor.h Fri Nov 20 08:28:11 2015 +0000
+++ b/Sensor.h Sun Nov 29 13:41:05 2015 +0000
@@ -1,3 +1,19 @@
+/** 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
+
+*/
#ifndef _SENSOR_H
#define SENSOR_H
#include "mbed.h"
@@ -5,12 +21,17 @@
class Sensor {
public:
-
- Sensor(PinName, float); //* Konsturktor klase Sensor koji uzima kao argument pin na kojem je spojen senzor može biti od p15-p20 *//
- //* i varijablu float kao koeficijent množenja vrijednosti dobivene ADC pretvorbom
- void read(); //* Funkcija read() bez povratnog argumenta ocitava vrijednost 10 puta i spremaju u float polje
- float calc(); //* Fukcija calac() raćuna srednju vrijednost readVal polja te vraća float varijablu sa stvarnom vrijednosti
- //* mjernog signala
+ /**
+ * @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;
--- a/ThingSpeak.cpp Fri Nov 20 08:28:11 2015 +0000
+++ b/ThingSpeak.cpp Sun Nov 29 13:41:05 2015 +0000
@@ -5,7 +5,7 @@
Serial pc(USBTX, USBRX);
-ThingSpeak::ThingSpeak(char* Key, const int Qt) : thingSpeakKey(Key) {
+ThingSpeak::ThingSpeak(char* Key) : thingSpeakKey(Key) {
thingSpeakUrl = "https://api.thingspeak.com/update";
urlBuffer[0] = 0;
fieldBuffer[0] = 0;
@@ -16,15 +16,15 @@
EthernetErr ethErr = eth.setup();
if(ethErr){
pc.printf("Error %d in ethernet setup.\r\n", ethErr);
- //* connect();
+ connect();
}
pc.printf("Ethernet setup OK\r\n");
}
-
+/*
void ThingSpeak::getIP() {
}
-
+*/
void ThingSpeak::setField(float field, int i) {
char fieldi;
char fieldShortBuff[8];
--- a/ThingSpeak.h Fri Nov 20 08:28:11 2015 +0000
+++ b/ThingSpeak.h Sun Nov 29 13:41:05 2015 +0000
@@ -1,3 +1,23 @@
+/** 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
+*/
+
#ifndef THINGSPEAK_H
#define THINGSPEAK_H
#define HOSTNAME "mbed"
@@ -6,27 +26,48 @@
#include "HTTPClient.h"
-class ThingSpeak {
-
- public:
-
- ThingSpeak(char*, const int);
- void connect();
- void getIP();
- void putUp();
- void setField(float, int);
- private:
-
- char* thingSpeakUrl;
- char* thingSpeakKey;
- char urlBuffer[511];
- char fieldBuffer[255];
- EthernetNetIf eth;
- EthernetErr ethErr;
- HTTPClient http;
- IpAddr ethIp;
- HTTPText resp;
- HTTPResult res;
+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
+#endif
\ No newline at end of file
--- a/main.cpp Fri Nov 20 08:28:11 2015 +0000
+++ b/main.cpp Sun Nov 29 13:41:05 2015 +0000
@@ -7,10 +7,10 @@
- ThingSpeak ts("074MPWFODR7JHD1K", 6);
+ ThingSpeak ts("074MPWFODR7JHD1K");
C12832 lcd(p5, p7, p6, p8, p11);
- Sensor current(p19,4);
- Sensor voltage(p20,24);
+ Sensor current(p19,4.65);
+ Sensor voltage(p20,16.23);
@@ -20,29 +20,22 @@
int i;
lcd.cls();
- lcd.locate(0,3);
+ lcd.locate(0,3);
+ lcd.printf("Ethernet Connecting ! \n");
ts.connect();
lcd.printf("Ethernet Connected ! \n");
- ts.getIP();
-
wait(1);
while(1){
-
- voltage.read();
- current.read();
- U = voltage.calc();
- I = current.calc();
- ina[0] = ina219.readRawReg(0x04); //* Current *//
+
+ 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 *//
-
+ ina[2] = ina219.readRawReg(0x03);//* Power *//
+
lcd.cls();
- lcd.locate(0,3);
- lcd.printf("V = %.2f V \n",U);
- lcd.printf("I = %.2f A \n",I);
- lcd.printf("P = %.2f W \n", U*I);
- lcd.locate(0,14);
+ 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]);
@@ -50,7 +43,8 @@
i = 1;
ts.setField(U, i++);
ts.setField(I, i++);
- for(int j = 0 ; j<= 3; j++)
+ ts.setField(I*U, i++);
+ for(int j = 0 ; j<= 2; j++)
ts.setField(ina[j], i++);
ts.putUp();