Temperature reading demo

Dependencies:   DHT libmDot mbed-rtos mbed

Files at this revision

API Documentation at this revision

Comitter:
SomeRandomBloke
Date:
Mon Sep 21 18:45:15 2015 +0000
Parent:
1:45cec6aea002
Child:
3:367aa95f9771
Commit message:
updates

Changed in this revision

libmDot.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
mbed-rtos.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
--- a/libmDot.lib	Thu Sep 03 23:36:45 2015 +0000
+++ b/libmDot.lib	Mon Sep 21 18:45:15 2015 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/teams/MultiTech/code/libmDot/#57978a837b2d
+http://mbed.org/teams/MultiTech/code/libmDot/#0b4eb17d07ae
--- a/main.cpp	Thu Sep 03 23:36:45 2015 +0000
+++ b/main.cpp	Mon Sep 21 18:45:15 2015 +0000
@@ -1,5 +1,5 @@
-/** mDot_display - Uses 160x128 SPI LCD display to show results of message
- * sending and receiving.
+/** mDot_DS18B20 - Simple mDot temperature sensor using Dallas Semiconductors DS18B20 OneWire temperature sensor.
+ *
  * Uses MultiTech mDot developer board http://www.multitech.com/models/94558010LF
  * Requires a MultiTech MultiConnect Conduit http://www.multitech.com/models/94557203LF
  *
@@ -7,7 +7,7 @@
  { "chan": 5, "codr": "4/5", "datr": "SF9BW125", "freq": "869.5",
  "lsnr": "8.8", "modu": "LORA", "rfch": 1, "rssi": -41, "seqn": 13,
  "size": 12, "timestamp": "2015-07-22T21:19:11Z", "tmst": 517590990,
- "payload": "{\"temperature\":21.3}", "eui": "00:80:00:00:00:00:9a:63", "_msg
+ "payload": "{\"tmp\":21.3}", "eui": "00:80:00:00:00:00:9a:63", "_msg
  id": "73bcd8dd.8c4328" }
  *
  */
@@ -30,20 +30,13 @@
 
 // mDot/dev board activity LED
 //#define ACTIVITY_LED PA_0
-// D13
+
+// DS18B20 OneWire pin
+// D13 on Dev Board, pin x on mDot
 #define DATA_PIN     PA_5
-// A0
+// A0 on Dev Board, pin x on mDot
 //#define DATA_PIN     PB_1
 
-// must use the hardware SPI pins
-//SPI device(SPI_MOSI, SPI_MISO, SPI_SCK);
-
-// SPI device defines
-#define MDOT_MOSI PA_7
-#define MDOT_MISO PA_6
-#define MDOT_SCK  PA_5
-#define MDOT_TFT_CS PA_4
-
 DS1820 probe(DATA_PIN);
 
 //void log_error(mDot* dot, const char* msg, int32_t retval);
@@ -58,39 +51,11 @@
     std::vector<uint8_t> send_data;
     std::vector<uint8_t> recv_data;
 
-//    int32_t next_tx;
-//    int32_t wait_time = 2;
-//    uint8_t iterations = 99;
-//    uint16_t txCount = 0;
-//    uint16_t txFailCount = 0;
-//    uint16_t rxCount = 0;
-//    uint16_t rxOkCount = 0;
-//    uint16_t noRxCount = 0;
-//    uint16_t rxFailCount = 0;
-//    bool initStatus = true;      // All intialised OK until told otherwise
     float temperature = 0.0;
 
     pc.baud(115200);
     pc.printf("mDot LoRa Temperature sensor\n\r");
-    /*    wait_ms(5000);
-        for(int i=0; i<10; i++ )
-            pc.printf(".");
-        pc.printf("\n\r");
-    */
-    /*
-        while( 1 ) {
-            // This takes upto 750mS, way too long. Change to 9 bit resolution if not already used.
 
-            probe.convertTemperature(true, DS1820::all_devices);         //Start temperature conversion, wait until ready
-    //        printf("It is %3.1fC\r\n", probe.temperature());
-            // Output data as JSON e.g. {"temperature":"21.3"}
-            temperature = probe.temperature();
-            pc.printf("Temperature %3.1f\r\n", temperature );
-            wait_ms(2000);
-        }
-
-    #ifdef bollocks
-    */
     // get a mDot handle
     dot = mDot::getInstance();
 
@@ -102,8 +67,11 @@
     std::string configNetworkName = dot->getNetworkName();
 
     // Check pin, if low then reset config.
-    
-    
+//       if ((ret = dot->setJoinMode( mDot::AUTO_OTA )) != mDot::MDOT_OK) {
+//            logError("failed to set join mode %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
+//        }
+
+
     if( config_network_name.compare(configNetworkName) != 0 ) {
         // Not saved config, reset
         logInfo("Setting Config");
@@ -125,11 +93,16 @@
 //    dot->setActivityLedPin( ACTIVITY_LED );
 //    dot->setActivityLedEnable(false);
 
-        dot->setJoinRetries( 5 );
-        dot->setTxDataRate( mDot::SF_9 );
+        // Have a decent nubmer of retries in connecting to LoRaWAN
+        dot->setJoinRetries( 3 );
+
+        // Set Spreading Factor, higher is lower data rate, smaller packets but longer range
+        // Lower is higher data rate, larger packets and shorter range.
+//        dot->setTxDataRate( mDot::SF_9 );
+    dot->setTxDataRate( mDot::SF_12 );
         dot->setTxPower( 14 );
         dot->setAck( 0 );       // 1 retries on Ack, 0 to disable
-
+ 
 //    Not applicable for 868MHz in EU
 //    if ((ret = dot->setFrequencySubBand(config_frequency_sub_band)) != mDot::MDOT_OK) {
 //        initStatus = false;
@@ -146,6 +119,10 @@
             logError("failed to set network password %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
         }
 
+        if ((ret = dot->setJoinMode( mDot::AUTO_OTA )) != mDot::MDOT_OK) {
+            logError("failed to set join mode %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
+        }
+
         logInfo("Saving Config");
 
         // Save config
@@ -155,8 +132,6 @@
     } else {
         logInfo("Using existing Config");
     }
-//    wait_ms(2000);
-    // Display protocol/connection info
 
     while ((ret = dot->joinNetwork()) != mDot::MDOT_OK) {
         logError("failed to join network [%d][%s]", ret, mDot::getReturnCodeString(ret).c_str());
@@ -183,20 +158,17 @@
 
         if ((ret = dot->send(send_data)) != mDot::MDOT_OK) {
             logError("failed to send: [%d][%s]", ret, mDot::getReturnCodeString(ret).c_str());
-
         } else {
-
             logInfo("send data: %s", Text::bin2hexString(send_data).c_str());
-
         }
 
         // Should  sleep here and wakeup after a set interval.
-
-        uint32_t sleep_time = 60;           //(dot->getNextTxMs() / 1000) + 10;
-        logInfo("going to sleep...");
+        uint32_t sleep_time = (dot->getNextTxMs() / 1000) + 60;
+        logInfo("going to sleep for %d seconds", sleep_time);
 
         // go to sleep and wake up automatically sleep_time seconds later
-        dot->sleep(sleep_time, mDot::RTC_ALARM, false);
+        dot->sleep(sleep_time, mDot::RTC_ALARM);
+
         /*
                 next_tx = dot->getNextTxMs() + 1;
                 logInfo("waiting %ld ms to transmit again", next_tx);
@@ -205,12 +177,6 @@
                 wait(wait_time);
         */
     }
-//#endif
+
     return 0;
 }
-/*
-void log_error(mDot* dot, const char* msg, int32_t retval)
-{
-    printf("%s - %ld:%s, %s\r\n", msg, retval, mDot::getReturnCodeString(retval).c_str(), dot->getLastError().c_str());
-}
-*/
\ No newline at end of file
--- a/mbed-rtos.lib	Thu Sep 03 23:36:45 2015 +0000
+++ b/mbed-rtos.lib	Mon Sep 21 18:45:15 2015 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed-rtos/#21b438192b0f
+http://mbed.org/users/mbed_official/code/mbed-rtos/#9d001ed5feec
--- a/mbed.bld	Thu Sep 03 23:36:45 2015 +0000
+++ b/mbed.bld	Mon Sep 21 18:45:15 2015 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/ba1f97679dad
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/4f6c30876dfa
\ No newline at end of file