No Description

Dependencies:   mbed picojson

Fork of Dragonfly-Examples by MultiTech

Files at this revision

API Documentation at this revision

Comitter:
dabraham
Date:
Tue Aug 29 00:28:43 2017 +0000
Parent:
2:31cc1a3ebcf3
Commit message:
No Message

Changed in this revision

MTSCellularInterface.lib Show annotated file Show diff for this revision Revisions of this file
examples/example_config.h Show annotated file Show diff for this revision Revisions of this file
examples/src/sms_example.cpp Show annotated file Show diff for this revision Revisions of this file
examples/src/tcp_example.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-os.lib Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
picojson.lib Show annotated file Show diff for this revision Revisions of this file
diff -r 31cc1a3ebcf3 -r e584561f4f6b MTSCellularInterface.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MTSCellularInterface.lib	Tue Aug 29 00:28:43 2017 +0000
@@ -0,0 +1,1 @@
+https://github.com/MultiTechSystems/MTSCellularInterface/#73dfa50ad26984bbdd6cbafe1ce37623a271bf28
diff -r 31cc1a3ebcf3 -r e584561f4f6b examples/example_config.h
--- a/examples/example_config.h	Thu Jul 06 16:24:06 2017 -0500
+++ b/examples/example_config.h	Tue Aug 29 00:28:43 2017 +0000
@@ -8,6 +8,8 @@
 #define SMS_EXAMPLE              1  // see sms_example.cpp
 #define TCP_EXAMPLE              2  // see tcp_example.cpp
 
+#define ACTIVE_EXAMPLE  SMS_EXAMPLE
+
 // Example program that will be compiled to run on target.
 #if !defined(ACTIVE_EXAMPLE)
 #define ACTIVE_EXAMPLE  TCP_EXAMPLE
diff -r 31cc1a3ebcf3 -r e584561f4f6b examples/src/sms_example.cpp
--- a/examples/src/sms_example.cpp	Thu Jul 06 16:24:06 2017 -0500
+++ b/examples/src/sms_example.cpp	Tue Aug 29 00:28:43 2017 +0000
@@ -9,13 +9,27 @@
 #include "MTSCellularInterface.h"
 #include "MTSLog.h"
 #include "example_config.h"
+#include <stdio.h>
+#include <string>
+#include <iostream>
+#include <sstream>
+#include "picojson.h"
+
+//using json = nlohmann::json;
 
 #if ACTIVE_EXAMPLE == SMS_EXAMPLE
 
 // Dragonfly debug port. 
 Serial debug_port(USBTX, USBRX);
+AnalogIn   ain(A0);
 
 int main(){
+    while(true){   
+        float per = ain * 3.7f * 100.0f;
+        printf("percentage: %1.0f%%\n", ain.read() * 7.4f * 100.0f);
+    wait(5);
+    }
+    
     //Sets the log level to INFO, higher log levels produce more log output.
     //Possible levels: NONE, FATAL, ERROR, WARNING, INFO, DEBUG and TRACE.
     //For the Dragonfly, installed on the UDK 2.0 board, messages are output on the
@@ -23,7 +37,7 @@
     // at 9600bps.    
     mts::MTSLog::setLogLevel(mts::MTSLog::INFO_LEVEL);
     //Sets the debug port to 115200bps.
-    debug_port.baud(115200);
+    debug_port.baud(9600);
 
     // Create an MTSCellularInterface object. Serial pins for the Dragonfly board that connect
     // to the on board cellular radio:
@@ -34,13 +48,19 @@
     logInfo("MTSCellularInterface Version %s", radio->get_library_version().c_str());
 
     //Modify to match your apn if you are using an HSPA radio with a SIM card.
-    const char apn[] = "";
+    const char apn[] = "rogers-core-appl1.apn";
     
-    //Phone number to send to and receive from. Must be in the form "1xxxxxxxxxx"
-    MTSCellularRadio::Sms txtmsg;
-    txtmsg.phone_number = "";
-    txtmsg.message = "Hello World! MTSCellularInterface is up and running!";
-
+    // Check if device is powered
+    //while(true){
+        if(radio->is_powered()){
+            logInfo("Device is powered");
+        }
+        else{
+            logInfo("Device is not powered");
+        }
+        //wait(10);
+    //}
+    
     //Set radio apn
     for (int i = 0; i < 10; i++) {
         if (i >= 10) {
@@ -50,10 +70,70 @@
             logInfo("Successfully set apn\n");
             break;
         } else {
+            logInfo("Failed to set apn\n");
             wait(1);
         }
     }
     
+    // Enable GPS
+    radio->gps_enable();
+    
+    // Get GPS position
+    while(true){
+        MTSCellularRadio::gpsData gps_data = radio->gps_get_position();        
+        bool gps_success = gps_data.success;
+        string latitude = gps_data.latitude;
+        string longitude = gps_data.longitude;
+        float hdop = gps_data.hdop;
+        float altitude = gps_data.altitude;
+        float fix = gps_data.fix;
+        string cog = gps_data.cog;
+        float kmhr = gps_data.kmhr;
+        float knots = gps_data.knots;
+        string timestamp = gps_data.timestamp;
+        
+        stringstream ss;
+        ss << gps_data.satellites;
+        string satellites = ss.str();
+                
+        if(gps_success == true){
+            picojson::object json_msg;
+            picojson::object gps_attributes;
+            
+            string JF_ID = "12345";
+            string event_ID = "1";
+ 
+            json_msg["JF_ID"] = picojson::value(JF_ID);
+            json_msg["event_ID"] = picojson::value(event_ID);
+            
+            gps_attributes["latitude"] = picojson::value(latitude);
+            gps_attributes["longitude"] = picojson::value(longitude);
+            gps_attributes["hdop"] = picojson::value(hdop);
+            gps_attributes["altitude"] = picojson::value(altitude);
+            gps_attributes["fix"] = picojson::value(fix);
+            gps_attributes["cog"] = picojson::value(cog);
+            gps_attributes["kmhr"] = picojson::value(kmhr);
+            gps_attributes["knots"] = picojson::value(knots);
+            gps_attributes["satellites"] = picojson::value(satellites);
+            gps_attributes["timestamp"] = picojson::value(timestamp);
+            
+            json_msg["gps_attributes"] = picojson::value(gps_attributes);
+                        
+            string GPSJSONString = picojson::value(json_msg).serialize();
+                
+            logInfo("The current JSON value is %s", GPSJSONString);
+        }
+        else{
+            logInfo("GPS Location failed");
+        }  
+        wait(10);
+    }
+/*    
+    //Phone number to send to and receive from. Must be in the form "1xxxxxxxxxx"
+    MTSCellularRadio::Sms txtmsg;
+    txtmsg.phone_number = "12045588580";
+    txtmsg.message = "Hello World! MTSCellularInterface is up and running!";    
+    
     //Delete any previously received SMS messages
     for (int i = 0; i < 10; i++) {
         if (i >= 10) {
@@ -93,8 +173,9 @@
         }
         wait(10);
     }
-    
+*/    
     return 0;
+
 }
 
 #endif
diff -r 31cc1a3ebcf3 -r e584561f4f6b examples/src/tcp_example.cpp
--- a/examples/src/tcp_example.cpp	Thu Jul 06 16:24:06 2017 -0500
+++ b/examples/src/tcp_example.cpp	Tue Aug 29 00:28:43 2017 +0000
@@ -4,19 +4,19 @@
 //
 // ** Configure the apn[] value below for MTQ-H5 or MTQ-LAT3 radios.
 // ** INTERVAL sets the number of seconds between repeated cycles of this example.
-
+ 
 #include "mbed.h"
 #include "MTSCellularInterface.h"
 #include "MTSLog.h"
 #include "example_config.h"
-
+ 
 #if ACTIVE_EXAMPLE == TCP_EXAMPLE
-
+ 
 // Dragonfly debug port. 
 Serial debug_port(USBTX, USBRX);
-
+ 
 #define INTERVAL 30
-
+ 
 int main(){
     //Sets the log level to INFO, higher log levels produce more log output.
     //Possible levels: NONE, FATAL, ERROR, WARNING, INFO, DEBUG and TRACE.
@@ -25,22 +25,22 @@
     // at 9600bps.    
     mts::MTSLog::setLogLevel(mts::MTSLog::INFO_LEVEL);
     //Sets the debug port to 115200bps.
-    debug_port.baud(115200);
-
+    debug_port.baud(9600);
+ 
     // Create an MTSCellularInterface object. Serial pins for the Dragonfly board that connect
     // to the on board cellular radio:
     // RADIO_TX = pin PC_7, RADIO_RX = pin PC_6
     MTSCellularInterface *radio = new MTSCellularInterface(RADIO_TX, RADIO_RX);
-
+ 
     // Print the MTSCellularInterface version
     logInfo("MTSCellularInterface Version %s", radio->get_library_version().c_str());
-
+ 
     //Modify to match your apn if you are using the MTQ-H5 or MTQ-LAT3.
-    const char apn[] = "";
-
+    const char apn[] = "rogers-core-appl1.apn";
+ 
     // Basic HTTP request.
-    std::string request = "GET / HTTP/1.1\r\nHost: developer.mbed.org\r\n\r\n";
-
+    std::string request = "POST / HTTP/1.1\r\nHost: httpbin.org/post\r\n\r\n";
+ 
     int cycle_count = 1;
     
     while (true) {       
@@ -50,7 +50,7 @@
             logWarning("radio not registered, try again in 2s");
             wait(2);
         }
-
+ 
         Timer tmr;  //mbed Timer has a 30 minute maximum timeout.
         tmr.start();
         while (radio->connect(apn) != NSAPI_ERROR_OK) {
@@ -59,32 +59,33 @@
             tmr.reset();
         }
         tmr.stop();
-
+ 
         // Show the network address
         const char *ip = radio->get_ip_address();
         logInfo("IP address is: %s\n", ip ? ip : "No IP");
-
+ 
         // Open a socket on the network interface, and create a TCP connection to mbed.org
+        
         TCPSocket socket;
-
+ 
         // Open a socket on the network interface.
         if (socket.open(radio) != NSAPI_ERROR_OK) {
             logWarning("socket did not open");
             socket.close();
             continue;
         }
-
+ 
         // Make a socket connection.
-        if (socket.connect("developer.mbed.org", 80) != NSAPI_ERROR_OK) {
+        if (socket.connect("httpbin.org", 80) != NSAPI_ERROR_OK) {
             logWarning("socket did not connect");
             socket.close();
             continue;
         }
-
+ 
         // Send tcp data
         int scount = socket.send(request.c_str(), request.size());
         logInfo("sent %d bytes: %s", scount, request.c_str());
-
+ 
         // Recieve and print. Give a couple seonds to receive.
         int size = 512;
         char rbuffer[size];
@@ -96,7 +97,7 @@
             int rcount = socket.recv(rbuffer, size-1);  //leave room for a null character
             if (rcount > 0) {
                 got_data = true;
-                while (rcount > 0) {
+                while (rcount > 0) {                    
                     logInfo("recv %d bytes: %s", rcount, rbuffer);
                     memset(rbuffer, 0, size);
                     rcount = socket.recv(rbuffer, size-1);
@@ -104,15 +105,23 @@
             }
         } while (rcv_timer < 2 && !got_data);
         
+        
+        //char rbuffer[64];
+        //int rcount = socket.recv(rbuffer, sizeof rbuffer);
+        //printf("recv %d [%.*s]\n", rcount, strstr(rbuffer, "\r\n")-rbuffer, rbuffer);
+        
+        
         // Close the socket to return its memory and bring down the network interface
         socket.close();
-
+ 
         radio->disconnect();
-
+ 
         logInfo("waiting %d seconds\r\n", INTERVAL);
         wait(INTERVAL);
     }
         
 }
-
+ 
 #endif
+ 
+         
\ No newline at end of file
diff -r 31cc1a3ebcf3 -r e584561f4f6b mbed-os.lib
--- a/mbed-os.lib	Thu Jul 06 16:24:06 2017 -0500
+++ b/mbed-os.lib	Tue Aug 29 00:28:43 2017 +0000
@@ -1,1 +1,1 @@
-https://github.com/ARMmbed/mbed-os/#5fff7e1daeb395aa3d1ecf3f9ec3f4fead3de0c2
+https://github.com/ARMmbed/mbed-os/#8828635da469162cf2854b5287561c663fb96e72
diff -r 31cc1a3ebcf3 -r e584561f4f6b mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Aug 29 00:28:43 2017 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/mbed_official/code/mbed/builds/a97add6d7e64
\ No newline at end of file
diff -r 31cc1a3ebcf3 -r e584561f4f6b picojson.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/picojson.lib	Tue Aug 29 00:28:43 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mimil/code/picojson/#2bb500b021e2