AMMP demonstration using Freescale FRDM-KL25Z and Adafruit CC3000 Arduino shield

Dependencies:   MMA8451Q NVIC_set_all_priorities TSI cc3000_hostdriver_mbedsocket mbed

Fork of AxedaGo-Freescale by Axeda Corp

Revision:
6:aeed0b3ebc34
Parent:
5:c99347399fb7
Child:
7:95a9dbe089e2
--- a/main.cpp	Tue Jan 14 21:25:58 2014 +0000
+++ b/main.cpp	Tue Jun 24 16:06:00 2014 +0000
@@ -1,18 +1,18 @@
 /* mbed Microcontroller Library
- * Copyright (c) 2006-2013 ARM Limited
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
+* Copyright (c) 2006-2013 ARM Limited
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
 #include "mbed.h"
 #include "cc3000.h"
 #include "main.h"
@@ -44,10 +44,10 @@
 
 
 /**
- *  \brief Print cc3000 information
- *  \param none
- *  \return none
- */
+*  \brief Print cc3000 information
+*  \param none
+*  \return none
+*/
 void print_cc3000_info() {
     uint8_t myMAC[8];
 
@@ -64,12 +64,12 @@
 }
 
 /**
- *  \brief Connect to SSID with a timeout
- *  \param ssid     Name of SSID
- *  \param key      Password
- *  \param sec_mode Security mode
- *  \return none
- */
+*  \brief Connect to SSID with a timeout
+*  \param ssid     Name of SSID
+*  \param key      Password
+*  \param sec_mode Security mode
+*  \return none
+*/
 void connect_to_ssid(char *ssid, char *key, unsigned char sec_mode) {
     printf("Connecting to SSID: %s. Timeout is 10s. \r\n",ssid);
     if (wifi.connect_to_AP((uint8_t *)ssid, (uint8_t *)key, sec_mode) == true) {
@@ -82,25 +82,29 @@
 
 
 /**
- *  \brief HTTP client demo
- *  \param  none
- *  \return int
- */
+*  \brief HTTP client demo
+*  \param  none
+*  \return int
+*/
 int main() {
 
     rled = 1;
     gled = 1;
     TSISensor touchSensor;
-    const char* SERVER_ADDRESS = "dev6-connect.axeda.com";
-    const int SERVER_PORT = 52689;
+    const char* SERVER_ADDRESS = "216.34.120.53";   //IP address for toolbox-stage-connect.axeda.com is 216.34.120.53
+                                                    //IP address for toolbox-connect.axeda.com is 216.34.120.52
+    const int SERVER_PORT = 80;
     char *MODEL = "Freescale";
-    char *SERIAL_NUM = "xkcd321"; 
-    char http_cmd[800];   
-    char buffer[800];  
+    char *SERIAL_NUM = "nlr__jrogers_axeda_com___6243311"; 
+    int http_cmd_sz=800;
+    char http_cmd[http_cmd_sz]; 
+    int buffer_sz=300;  
+    char buffer[buffer_sz];  
     int returnCode = 0;
-    int BGL=0;
+    int weight=0;
     TCPSocketConnection socket;
     
+        
     float accels[3];
     float resting,reading;
     float THRESHOLD = 0.15;
@@ -141,12 +145,17 @@
     printf("  gateway                = %d.%d.%d.%d \r\n", ipinfo2.aucDefaultGateway[3], ipinfo2.aucDefaultGateway[2], ipinfo2.aucDefaultGateway[1], ipinfo2.aucDefaultGateway[0]);
     printf("  DNS IP Address         = %d.%d.%d.%d \r\n", ipinfo2.aucDNSServer[3], ipinfo2.aucDNSServer[2], ipinfo2.aucDNSServer[1], ipinfo2.aucDNSServer[0]);
 
+
+
+    
     wait(0.7);
     acc.getAccAllAxis( accels );
     resting = abs(accels[0]) + abs(accels[1]) + abs(accels[2]);
     printf("Set up resting accelerometer - %.2f\r\n", resting);
     wait(0.1);
 
+
+        
     while(1)
     {
 
@@ -160,28 +169,34 @@
             gled = 1;
             
             printf("Before connect\r\n");
+            //socket.connect(SERVER_ADDRESS, SERVER_PORT);
             while ( socket.connect(SERVER_ADDRESS, SERVER_PORT)  < 0) {
-                printf("Unable to connect to (%s) on port (%d) \r\n", SERVER_ADDRESS, SERVER_PORT);
+              printf("Unable to connect to (%s) on port (%d) \r\n", SERVER_ADDRESS, SERVER_PORT);
                 wait(1);
                 printf(" - retring to connect");
             }
             printf( "connected");
-            BGL = position * 300;
-            sprintf(http_cmd,  "POST /ammp/data/1/%s!%s HTTP/1.1\r\nContent-type: application/json\r\nContent-Length: 52\r\n\r\n{\"data\":[{\"dataItems\":{\"bar\":\"camp\",\"BGL\":%d}}]}\r\n\r\n", MODEL, SERIAL_NUM, BGL);
-            socket.send_all(http_cmd, sizeof(http_cmd)-1);
+            weight = position * 300;
+            printf("\n%d\n", weight);
+           snprintf(http_cmd, http_cmd_sz, "POST /ammp/data/1/%s!%s HTTP/1.1\r\nContent-type: application/json\r\nContent-Length: 52\r\n\r\n{\"data\":[{\"dataItems\":{\"weight\":%d}}]}\r\n\r\n", MODEL, SERIAL_NUM, weight);
+            socket.send_all(http_cmd, http_cmd_sz-1);
      
-            returnCode = socket.receive(buffer, sizeof(buffer)-1);
+            returnCode = socket.receive(buffer, buffer_sz-1);
         
             buffer[returnCode] = '\0';
             printf("Sent->%s<-\r\n",http_cmd);
             printf("Received %d chars from server:\n\r%s\n", returnCode, buffer);
-        
+            
             socket.close();
             printf("Socket closed\r\n");
             rled = 0;
             gled = 0;
+        
+        //memset null
+        memset(buffer, '\0', buffer_sz);
+        memset(http_cmd, '\0', http_cmd_sz);
         }
-    
+
     }
     
 }