Transmit pressure/temperature reading once per hour from xDot to iupivot server

Dependencies:   ATParser MPL3115A2 mbed

Files at this revision

API Documentation at this revision

Comitter:
csinders
Date:
Fri Apr 06 16:45:35 2018 +0000
Parent:
3:59fbf4f41f69
Commit message:
Code working for Lab 9, just have to set up in Luddy.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 59fbf4f41f69 -r 9235d082b6a3 main.cpp
--- a/main.cpp	Fri Apr 06 15:24:35 2018 +0000
+++ b/main.cpp	Fri Apr 06 16:45:35 2018 +0000
@@ -31,6 +31,7 @@
         if (buf[i] == '\n') { 
         // Read new line so check to see if we got an OK or Error
         // else keep reading til we get one
+        //pc.printf("The message from the device is %s\r\n",buf);
             if (!strncmp("OK",buf,2)) {
                 //pc.printf("I compared against %s and got OK\r\n",buf);
                 return 1;
@@ -44,7 +45,7 @@
             return 0;
         }
     }
-    return 0;
+    return confirmOK();
 }
 /*  Sends a message to the xDot
     Messages are expected to end in \n so that an OK confirmation will be 
@@ -65,16 +66,19 @@
     int i = 0;
     while (i < size) { 
         device.putc(*message);
-        pc.printf("putting %c on device\n\r", *message++);
+        //wait_ms(500); // Not succesfully sending the message unless it waits.
+        //pc.printf("putting %c on device\n\r", *message);
+        message++;
         i++;
     }
 }
 int main() {
     pc.baud(115200);
     device.baud(115200);
-    ATParser atp = ATParser(device,"\r\n",256,2000,false);
+   
+    pc.printf("Starting program\n\r");
     
-    pc.printf("Starting program\n\r");
+    myled = 0;
     
     if (!sendAtMessage("AT\n")) { 
         pc.printf("xDot not responding to message\n\r");
@@ -92,25 +96,55 @@
     }
     //Set the frequency sub band
     char frequencySubBand[] = "AT+FSB=1\n";
-    if (sendAtMessage(frequencySubBand)) { 
-        //pc.printf("Network frequency SubBand successfully set\n\r");
+    if (!sendAtMessage(frequencySubBand)) { 
+        pc.printf("Network frequency SubBand not successfully set\n\r");
     }
     //Join the network
     char joinNetwork[] = "AT+JOIN\n"; // Unable to join network atm.
     if (!sendAtMessage(joinNetwork)) { 
         pc.printf("Failed to joined the network\n\r");
     }
-    
+    pc.printf("I got here\r\n");
+    int i = 0; 
+    for (i = 0; i < 48; i++) {
+        int tempBufSize = 4;
+        int presBufSize = 6;
+        double temp = pressure_sensor.getTemperature();
+        char tempBuf[tempBufSize];
+        double pres = pressure_sensor.getPressure();
+        char presBuf[presBufSize];
+        //pc.printf("Current temp is %f\n\r",temp);
+        //pc.printf("Current pres is %f\n\r",pres);
+        sprintf(tempBuf, "%2.1f",temp);
+        sprintf(presBuf, "%4.1f",pres);
+        //pc.printf("After convert with sprintf temp = %s\n\r",tempBuf);
+        //pc.printf("After convert with sprintf pres = %s\n\r",presBuf);
+        sendAtMessageNACK("AT+SEND=",8);
+        sendAtMessageNACK(tempBuf,tempBufSize);
+        sendAtMessageNACK(",",1);
+        sendAtMessageNACK(presBuf,presBufSize);
+        //wait_ms(500);
+        if (sendAtMessage("\n")) { 
+            pc.printf("message succesfully sent\n\r");
+            myled = 1;
+        }  else {
+            pc.printf("Failed to send the message for some reason\r\n");   
+        }
+        
+        wait(1000);
+       
+    } 
     
     //When an s is read from the serial pc,
     // read the current pressure/temperature from the I2C pressure sensor
     // and send it to the MQTT server pivot.iuiot
-    
     //Unsure of what size to set Buffer so that it doesn't go over
     //when trying to send a message
+    
+    /*
     while(1) {
         if (pc.readable()) {
-            pc.printf("pc.readable\r\n");
+            //pc.printf("pc.readable\r\n");
             if (pc.getc() == 's') { 
                 pc.printf("I recieved an s\r\n");
                 int tempBufSize = 4;
@@ -132,11 +166,13 @@
                 wait_ms(500);
                 if (sendAtMessage("\n")) { 
                     pc.printf("message succesfully sent\n\r");
-                }  
-                //void memset(* void tmp,0,100);
+                }  else {
+                    pc.printf("Failed to send the message for some reason\r\n");   
+                }
             }
         }
     }
+    */
     
     /*
     while(1) {