mDot_TTN_OTAA_Node_send_data_as_string

Dependencies:   mbed mbed-rtos BME280 DS1820

Files at this revision

API Documentation at this revision

Comitter:
ScheepersJ
Date:
Sun Nov 01 16:04:48 2020 +0000
Parent:
15:8a0ebf59b8bb
Commit message:
mDot_TTN_OTAA_Node_send_data_as_string

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
diff -r 8a0ebf59b8bb -r 4aa655bf72ba libmDot.lib
--- a/libmDot.lib	Wed May 11 06:26:11 2016 +0000
+++ b/libmDot.lib	Sun Nov 01 16:04:48 2020 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/teams/MultiTech/code/libmDot/#121e4c454964
+https://os.mbed.com/users/ScheepersJ/code/libmDot/#26f7d62d808c
diff -r 8a0ebf59b8bb -r 4aa655bf72ba main.cpp
--- a/main.cpp	Wed May 11 06:26:11 2016 +0000
+++ b/main.cpp	Sun Nov 01 16:04:48 2020 +0000
@@ -1,11 +1,10 @@
-/** mDot_TTN_Node - Simple mDot temperature sensor using Dallas Semiconductors DS18B20 OneWire temperature sensor.
+/** mDot_TTN_Node - Simple mDot temperature and soil moisture sensor using Dallas Semiconductors DS18B20 OneWire temperature sensor and Capacitive Soil Moisture Sensor V1.2.
  * It used the AUTO_OTA join mode with parameters for The Things Network.
  *
  *
  * Uses MultiTech mDot developer board http://www.multitech.com/models/94558010LF
- * Requires a MultiTech MultiConnect Conduit http://www.multitech.com/models/94557203LF
+ * Requires a TTN gateway to sensd data
  * http://www.multitech.net/developer/software/lora/conduit-mlinux-convert-to-basic-packet-forwarder/
- * http://forum.thethingsnetwork.org/t/setting-up-multitech-conduit-gateway-for-ttn/216/35
  *
  * Register a device and generate a random AppKey for the currently used application Id:
  * (You need to use your own device IDs, the ones shown here are examples only)
@@ -37,7 +36,6 @@
 
 #include "mbed.h"
 #include "DS1820.h"
-//#include "BME280.h"
 #include "mDot.h"
 #include "MTSLog.h"
 #include "MTSText.h"
@@ -50,9 +48,9 @@
 #define MAX(a,b) (((a)>(b))?(a):(b))
 
 // AppEUI
-uint8_t AppEUI[8]={0x70, 0xB3, 0xD5, 0x00, 0x00, 0x00, 0x00, 0x00};
+uint8_t AppEUI[8]={ 0x70, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x6F };
 // AppKey
-uint8_t AppKey[16]={0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F};
+uint8_t AppKey[16]={ 0x18, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x9E };
 
 // Some defines for the LoRa configuration
 /*
@@ -65,15 +63,8 @@
  * DR4 - SF8BW125
  * DR5 - SF7BW125
  * DR6 - SF7BW250
- *
- * US915 Datarates
- * ---------------
- * DR0 - SF10BW125
- * DR1 - SF9BW125
- * DR2 - SF8BW125
- * DR3 - SF7BW125
- * DR4 - SF8BW500
  */
+
 #define LORA_SF mDot::DR5
 #define LORA_ACK 0
 #define LORA_TXPOWER 14
@@ -82,16 +73,19 @@
 static uint8_t config_frequency_sub_band = 1;
 
 // DS18B20 OneWire pin
-// D13 on Dev Board, pin 18 on mDot, Compatible with Oxford Flood Network PCB temperature sensor.
-//#define DATA_PIN     PA_5
-// A1 on Dev Board, pin 19 on mDot
+// D2 on Dev Board, pin 13 on mDot
 #define DATA_PIN     PC_13
 
 // Temperature sensor object
-DS1820 probe(DATA_PIN);
+DS1820 probe(DATA_PIN); //Temprature in
 
-// BME280 Temperature/Humidity/Pressure sensor
-//BME280 sensor(I2C_SDA, I2C_SCL);
+//Capacitive Soil Moisture Sensor V1.2 No1
+// A0 on Dev Board, pin 20 on mDot
+AnalogIn A1(PB_1); //Analog 1 in for Soil Moisture
+
+//Capacitive Soil  Moisture Sensor V1.2 No2
+// A1 on Dev Board, pin 19 on mDot
+AnalogIn A2(PB_0); //Analog 2 in for Soil Moisture
 
 // Serial via USB for debugging only
 Serial pc(USBTX,USBRX);
@@ -106,8 +100,6 @@
     std::vector<uint8_t> nwkKey;
 
     float temperature = 0.0;
-    float humidity = 0.0;
-    float pressure = 0.0;
 
     pc.baud(115200);
     pc.printf("TTN OTAA mDot LoRa Temperature sensor\n\r");
@@ -248,17 +240,20 @@
 
     char dataBuf[50];
     while( 1 ) {
-            // Output data as JSON e.g. {"t":21.3}
-//            temperature = sensor.getTemperature();
-//            humidity = sensor.getHumidity();
-//            pressure = sensor.getPressure();
+
+            float analog1; //Analog 1 in for Soil Moisture No.1
+            analog1 = A1.read() * 3.3;
+
+            float analog2; //Analog 2 in for Soil Moisture No.2
+            analog2 = A2.read() * 3.3;
 
             //Start temperature conversion, wait until ready
         probe.convertTemperature(true, DS1820::all_devices);
             // Output data as JSON e.g. {"t":21.3}
         temperature = probe.temperature();
-        sprintf(dataBuf, "{\"t\":%3.1f}", temperature );
-//            sprintf(dataBuf, "%3.1f,%3.1f,%04.2f", temperature,humidity,pressure );
+
+        //sprintf(dataBuf, "%3.1f", temperature );
+        sprintf(dataBuf, "%3.1f,%3.1f,%04.2f", temperature , analog1 , analog2 );
         pc.printf("%s\n",dataBuf);
             send_data.clear();
             // probably not the most efficent way to do this
@@ -273,8 +268,8 @@
 
            // Should  sleep here and wakeup after a set 5 minute interval.
             // in the 868 (EU) frequency band, we need to wait until another channel is available before transmitting again
-            uint32_t sleep_time = std::max((uint32_t)300000, (uint32_t)dot->getNextTxMs()) / 1000;
-//wait_ms(2000);
+            uint32_t sleep_time = std::max((uint32_t)600000, (uint32_t)dot->getNextTxMs()) / 1000;
+
             // go to sleep and wake up automatically sleep_time seconds later
             dot->sleep(sleep_time, mDot::RTC_ALARM);
     }