ublox SupportTest with temperature response

Dependencies:   C027_Support

Fork of C027_SupportTest by u-blox

Files at this revision

API Documentation at this revision

Comitter:
Adfontes
Date:
Tue May 30 11:14:41 2017 +0000
Parent:
33:e27f40fada64
Commit message:
added temperature response

Changed in this revision

C027_Support.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r e27f40fada64 -r a7f205c92059 C027_Support.lib
--- a/C027_Support.lib	Thu Aug 11 07:12:02 2016 +0000
+++ b/C027_Support.lib	Tue May 30 11:14:41 2017 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/teams/ublox/code/C027_Support/#7b747676de86
\ No newline at end of file
+http://mbed.org/teams/ublox/code/C027_Support/#dafbbf31bf76
diff -r e27f40fada64 -r a7f205c92059 main.cpp
--- a/main.cpp	Thu Aug 11 07:12:02 2016 +0000
+++ b/main.cpp	Tue May 30 11:14:41 2017 +0000
@@ -24,15 +24,21 @@
 /*! The APN of your network operator SIM, sometimes it is "internet" check your 
     contract with the network operator. You can also try to look-up your settings in 
     google: https://www.google.de/search?q=APN+list */
-#define APN         NULL
+#define APN         "internet.mts.ru"
 //! Set the user name for your APN, or NULL if not needed
-#define USERNAME    NULL
+#define USERNAME    "mts"
 //! Set the password for your APN, or NULL if not needed
-#define PASSWORD    NULL 
+#define PASSWORD    "mts" 
 //------------------------------------------------------------------------------------
 
 //#define CELLOCATE
 
+#define LM70_SPI_MOSI  PB_5
+#define LM70_SPI_MISO  PB_4
+#define LM70_SPI_SCK   PB_3
+#define LM70_SPI_CS    PA_4
+#define LM70_LSB       0.25
+
 int main(void)
 {
     int ret;
@@ -43,13 +49,13 @@
 #endif
 
     // Create the GPS object
-#if 1   // use GPSI2C class
+#if 0   // use GPSI2C class
     GPSI2C gps;
 #else   // or GPSSerial class 
-    GPSSerial gps; 
+    GPSSerial gps(PA_11, PA_12); 
 #endif
     // Create the modem object
-    MDMSerial mdm; // use mdm(D1,D0) if you connect the cellular shield to a C027
+    MDMSerial mdm(D8, D2); // use mdm(D1,D0) if you connect the cellular shield to a C027
     //mdm.setDebug(4); // enable this for debugging issues 
     // initialize the modem 
     MDMParser::DevStatus devStatus = {};
@@ -204,9 +210,76 @@
     mdm.cellLocConfigSensor(1);   // Deep scan mode
     //mdm.cellUnsolIndication(1);
 #endif
-    //DigitalOut led(LED1);
+
+    SPI lm70_spi(LM70_SPI_MOSI, LM70_SPI_MISO, LM70_SPI_SCK);
+    DigitalOut lm70_cs(LM70_SPI_CS, 1);
+    
+    const int lm70Period = 60;  // 1 minutes in seconds
+    unsigned int k = lm70Period * 1000/wait;
+    
+    uint8_t spi_buf[2];
+    uint16_t* temp = (uint16_t*)spi_buf;
+    float fT = 0.0;
+    char strT[128] = "";
+    
+    lm70_spi.frequency(125000);
+    
+    DigitalOut led(LED1);
     while (!abort) {
-    //    led = !led;
+        led = !led;
+    
+        if( k++ == lm70Period * 1000/wait )
+        {
+            k = 0;
+            
+            lm70_cs = 0;
+            spi_buf[1] = lm70_spi.write(0x00);
+            spi_buf[0] = lm70_spi.write(0x00);
+            lm70_cs = 1;
+            if( (*temp & 0x001C) != 0x001C )
+            {
+                printf("T: Error!\r\n");
+            }
+            else
+            {
+                fT = ((int16_t)(*temp) >> 5) * LM70_LSB;
+                printf("T: %.2f\r\n", fT);
+            }
+            
+            if( mdmOk )
+            {
+                // join the internet connection 
+                MDMParser::IP ip = mdm.join(APN,USERNAME,PASSWORD);
+                if( ip == NOIP )
+                    printf("Not able to join network");
+                else
+                {
+                    mdm.dumpIp(ip);
+                    printf("Make a Http Post Request\r\n");
+                    int socket = mdm.socketSocket(MDMParser::IPPROTO_TCP);
+                    if( socket >= 0 )
+                    {
+                        mdm.socketSetBlocking(socket, 10000);
+                        if( mdm.socketConnect(socket, "api.thingspeak.com", 80) )
+                        {
+                            char http[128] = "";
+                            sprintf(http, "GET /update?key=55JOP6J3OOKJNO3R&field1=%.1f\r\n\r\n", fT);
+                            mdm.socketSend(socket, http, sizeof(http)-1);
+                        
+                            ret = mdm.socketRecv(socket, buf, sizeof(buf)-1);
+                            if( ret > 0 )
+                                printf("Socket Recv \"%*s\"\r\n", ret, buf);
+                            mdm.socketClose(socket);
+                        }
+                        mdm.socketFree(socket);
+                    }
+                
+                    // disconnect  
+                    mdm.disconnect();
+                }
+            }
+        }
+    
 #ifndef CELLOCATE
         while ((ret = gps.getMessage(buf, sizeof(buf))) > 0)
         {
@@ -286,6 +359,12 @@
                         reply = *link ? link : "I don't know"; // reply wil location link
                     else if (strstr(buf, /*s*/"hutdown"))
                         abort = true, reply = "bye bye";
+                        else
+                            if(strstr(buf, /*w*/"hat is the weather today"))
+                            {
+                                sprintf(strT, "It's %.2f degrees centigrade", fT);
+                                reply = strT;
+                            }
                     printf("Send SMS reply \"%s\" to \"%s\"\r\n", reply, num);
                     mdm.smsSend(num, reply);
                 }