I am in my way
Dependencies: ublox-at-cellular-interface ublox-cellular-base C12832 LM75B ublox-cellular-base-n2xx ublox-at-cellular-interface-n2xx
Revision 1:135f5adc847c, committed 2019-04-29
- Comitter:
- reeml3
- Date:
- Mon Apr 29 12:40:03 2019 +0000
- Parent:
- 0:0044354f0061
- Commit message:
- I am in my way
Changed in this revision
| 973263a70be0/main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/973263a70be0/main.cpp Sat Apr 27 10:16:39 2019 +0000
+++ b/973263a70be0/main.cpp Mon Apr 29 12:40:03 2019 +0000
@@ -35,8 +35,8 @@
// Sensor Pin and Object Activation
C12832 lcd(D11, D13, D12, D7, D10);
LM75B sensor(D14,D15); // 1st Temperature sensor
-AnalogIn pot2 (A1); // 2nd Potentiometer sensor
-
+//AnalogIn pot2 (A1); // 2nd Potentiometer sensor
+AnalogIn moisture(A0);
#define INTERFACE_CLASS UbloxATCellularInterface //This interface is used to initiate modem commands for sending data to sever
// The credentials of the SIM in the board. If PIN checking is enabled
@@ -55,6 +55,26 @@
// The user button
volatile bool buttonPressed = false;
+
+float map(float in, float inMin, float inMax, float outMin, float outMax) {
+ // check it's within the range
+ if (inMin<inMax) {
+ if (in <= inMin)
+ return outMin;
+ if (in >= inMax)
+ return outMax;
+ } else { // cope with input range being backwards.
+ if (in >= inMin)
+ return outMin;
+ if (in <= inMax)
+ return outMax;
+ }
+ // calculate how far into the range we are
+ float scale = (in-inMin)/(inMax-inMin);
+ // calculate the output.
+ return outMin + scale*(outMax-outMin);
+}
+
static void good() {
ledGreen = 0;
ledBlue = 1;
@@ -106,10 +126,10 @@
#endif
SocketAddress tcpServer;
- char deviceID[20] = "357520073945921";
+ char deviceID[20] = "357520073946010";
char buf[1024]; // this buffer is used to send POST data to platform
char temp[50]; // this buffer will be used to store sensor values
- char pot[50]; // this buffer will be used to store 2nd sensor values
+ char soil[50]; // this buffer will be used to store 2nd sensor values
int x;
#ifdef TARGET_UBLOX_C027
@@ -178,7 +198,7 @@
lcd.printf("%s", temp); // Display Temperature value on LCD
- snprintf(buf, sizeof buf, "%s%s%s%s%s%s", "POST /ksu/?deviceID=",deviceID,"&",temp,"&unit=T"," HTTP/1.0\r\n\r\n");
+ snprintf(buf, sizeof buf, "%s%s%s%s%s%s", "POST /ksu/?deviceID=",deviceID,"&",temp,"&unit=C"," HTTP/1.0\r\n\r\n");
printf("Output string is %s",buf);
@@ -206,19 +226,22 @@
/////////////////////////////////// Sending 2nd Sensor Value //////////////////////
-
+ float final_2 = moisture.read() * 3300;
+ uint16_t meas = (moisture.read_u16());
+ float final_1 = (float) 3300 / 65535 * (float) meas;
+ float newval = map(final_1,660,770,100,0);
lcd.cls();
lcd.locate(0,3);
- snprintf(pot,sizeof pot,"POT=%.1f", (float)pot2); //Sensor Key "Temperature" and Value is Sensor Data
+ snprintf(soil,sizeof soil,"Moisture=%.1f", (float)map(final_1,660,770,100,0)); //Sensor Key "Moisture" and Value is Sensor Data
- lcd.printf("%s", pot); // Display Temperature value on LCD
+ lcd.printf("%s", soil); // Display Moisture value on LCD
wait(2.0);
- snprintf(buf, sizeof buf, "%s%s%s%s%s%s", "POST /ksu/?deviceID=",deviceID,"&",pot,"&unit=R"," HTTP/1.0\r\n\r\n");
+ snprintf(buf, sizeof buf, "%s%s%s%s%s%s", "POST /ksu/?deviceID=",deviceID,"&",soil,"&unit=%"," HTTP/1.0\r\n\r\n");
printf("Output string is %s",buf);