![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
My variant
Dependencies: LIS3DH LM75B LPS331 hts221 mbed
Fork of Skywire_Demo by
main.cpp@10:5974a7b2cf38, 2016-03-29 (annotated)
- Committer:
- kholland
- Date:
- Tue Mar 29 20:03:13 2016 +0000
- Revision:
- 10:5974a7b2cf38
- Parent:
- 9:555eb4259fc6
- Child:
- 11:5e69c9fbdfdc
Support for HE910, LE910, GE910, DE910, ELS31 (CAT1); Added support for new sensors
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kholland | 4:e7a79d3542e1 | 1 | /* main.cpp */ |
kholland | 10:5974a7b2cf38 | 2 | /* v3.0 |
kholland | 10:5974a7b2cf38 | 3 | * Copyright (C) 2016 nimbelink.com, MIT License |
kholland | 4:e7a79d3542e1 | 4 | * |
kholland | 4:e7a79d3542e1 | 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
kholland | 4:e7a79d3542e1 | 6 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
kholland | 4:e7a79d3542e1 | 7 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
kholland | 4:e7a79d3542e1 | 8 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
kholland | 4:e7a79d3542e1 | 9 | * furnished to do so, subject to the following conditions: |
kholland | 4:e7a79d3542e1 | 10 | * |
kholland | 4:e7a79d3542e1 | 11 | * The above copyright notice and this permission notice shall be included in all copies or |
kholland | 4:e7a79d3542e1 | 12 | * substantial portions of the Software. |
kholland | 4:e7a79d3542e1 | 13 | * |
kholland | 4:e7a79d3542e1 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
kholland | 4:e7a79d3542e1 | 15 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
kholland | 4:e7a79d3542e1 | 16 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
kholland | 4:e7a79d3542e1 | 17 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
kholland | 4:e7a79d3542e1 | 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
kholland | 4:e7a79d3542e1 | 19 | */ |
kholland | 0:3095958bc639 | 20 | |
kholland | 10:5974a7b2cf38 | 21 | /* |
kholland | 10:5974a7b2cf38 | 22 | * DESCRIPTION |
kholland | 10:5974a7b2cf38 | 23 | * This code updated sensor data on the Nimbelink ST Development Kit (NL-AB-ST-NCL) and sends |
kholland | 10:5974a7b2cf38 | 24 | * the information to www.dweet.io using the Thingname "DeviceID". That information can be |
kholland | 10:5974a7b2cf38 | 25 | * viewed using a Freeboard at www.freeboard.io (account required). Depending on your |
kholland | 10:5974a7b2cf38 | 26 | * ST Development Kit version, clone the following freeboard: |
kholland | 10:5974a7b2cf38 | 27 | * Rev A (Legacy): https://freeboard.io/board/jqlneI |
kholland | 10:5974a7b2cf38 | 28 | * Rev B (Current): https://freeboard.io/board/LhnbrX |
kholland | 10:5974a7b2cf38 | 29 | * |
kholland | 10:5974a7b2cf38 | 30 | * Please consult the wiki for more information |
kholland | 10:5974a7b2cf38 | 31 | */ |
kholland | 10:5974a7b2cf38 | 32 | |
kholland | 10:5974a7b2cf38 | 33 | /* |
kholland | 10:5974a7b2cf38 | 34 | * INSTRUCTIONS FOR USING THIS CODE |
kholland | 10:5974a7b2cf38 | 35 | * 1. Under the "DEFINE THE SKYWIRE MODEM" section of the code, uncomment the modem that you |
kholland | 10:5974a7b2cf38 | 36 | * are using to enable to proper setup and features of your Skywire modem. |
kholland | 10:5974a7b2cf38 | 37 | * |
kholland | 10:5974a7b2cf38 | 38 | * NOTE: Make sure the other Skywire modems listed are commented out. |
kholland | 10:5974a7b2cf38 | 39 | * |
kholland | 10:5974a7b2cf38 | 40 | * 2. Change the "DeviceID" to a unique identifier for your Nucleo board. One recommendation |
kholland | 10:5974a7b2cf38 | 41 | * would be to use the MEID/IMEI of your Skywire Modem. |
kholland | 10:5974a7b2cf38 | 42 | * |
kholland | 10:5974a7b2cf38 | 43 | * 3. If applicable, change the APN for your Skywire Modem. |
kholland | 10:5974a7b2cf38 | 44 | */ |
kholland | 10:5974a7b2cf38 | 45 | |
kholland | 0:3095958bc639 | 46 | #include "mbed.h" |
kholland | 0:3095958bc639 | 47 | #include "LPS331.h" |
kholland | 0:3095958bc639 | 48 | #include "LIS3DH.h" |
kholland | 0:3095958bc639 | 49 | #include "LM75B.h" |
kylerodgers | 7:00d66e743603 | 50 | #include "hts221.h" |
kholland | 10:5974a7b2cf38 | 51 | #include <string> |
kholland | 0:3095958bc639 | 52 | |
kholland | 10:5974a7b2cf38 | 53 | /* |
kholland | 10:5974a7b2cf38 | 54 | * DEFINE THE SKYWIRE MODEM |
kholland | 10:5974a7b2cf38 | 55 | * Uncomment only the modem that you are using. |
kholland | 10:5974a7b2cf38 | 56 | * Make sure only one modem is uncommented! |
kholland | 10:5974a7b2cf38 | 57 | */ |
kholland | 10:5974a7b2cf38 | 58 | //#define NL_SW_1xRTT_V // Verizon 2G Modem - CE910-DUAL |
kholland | 10:5974a7b2cf38 | 59 | //#define NL_SW_1xRTT_S // Sprint 2G Modem - CE910-DUAL |
kholland | 10:5974a7b2cf38 | 60 | //#define NL_SW_1xRTT_A // Aeris 2G Modem - CE910-DUAL |
kholland | 10:5974a7b2cf38 | 61 | //#define NL_SW_GPRS // AT&T/T-Mobile 2G Modem |
kholland | 10:5974a7b2cf38 | 62 | //#define NL_SW_EVDO_V // Verizon 3G Modem |
kholland | 10:5974a7b2cf38 | 63 | //#define NL_SW_EVDO_A // Aeris 3G Modem |
kholland | 10:5974a7b2cf38 | 64 | //#define NL_SW_HSPAP // AT&T/T-Mobile 3G Modem |
kholland | 10:5974a7b2cf38 | 65 | //#define NL_SW_HSPAPG // AT&T/T-Mobile 3G Modem w/ GPS |
kholland | 10:5974a7b2cf38 | 66 | //#define NL_SW_HSPAPE // GSM 3G Modem, EU |
kholland | 10:5974a7b2cf38 | 67 | //#define NL_SW_LTE_TSVG // Verizon 4G LTE Modem |
kholland | 10:5974a7b2cf38 | 68 | //#define NL_SW_LTE_TNAG // AT&T/T-Mobile 4G LTE Modem |
kholland | 10:5974a7b2cf38 | 69 | //#define NL_SW_LTE_TEUG // GSM 4G LTE Modem, EU |
kholland | 10:5974a7b2cf38 | 70 | //#define NL_SW_LTE_GELS3 // VZW LTE Cat 1 Modem |
kholland | 10:5974a7b2cf38 | 71 | |
kholland | 10:5974a7b2cf38 | 72 | /* --CHANGE THIS FOR YOUR SETUP-- */ |
kholland | 10:5974a7b2cf38 | 73 | #define DeviceID "yourDeviceIDhere" //Freeboard DweetIO unique ID |
kholland | 0:3095958bc639 | 74 | |
kholland | 10:5974a7b2cf38 | 75 | /* --CHANGE THIS FOR YORU SETUP (IF APPLICABLE)-- */ |
kholland | 10:5974a7b2cf38 | 76 | #if defined NL_SW_HSPAP || defined NL_SW_HSPAPG || defined NL_SW_HSPAPE || defined NL_SW_LTE_TSVG || defined NL_SW_LTE_TNAG || defined NL_SW_LTE_TEUG || defined NL_SW_LTE_GELS3 |
kholland | 10:5974a7b2cf38 | 77 | std::string APN = "yourAPNhere"; |
kholland | 10:5974a7b2cf38 | 78 | #endif |
kholland | 0:3095958bc639 | 79 | |
kholland | 10:5974a7b2cf38 | 80 | DigitalOut myled(LED1); // Main LED |
kholland | 10:5974a7b2cf38 | 81 | DigitalOut skywire_en(PA_6); // Skywire Enable |
kholland | 10:5974a7b2cf38 | 82 | DigitalOut skywire_rts(PA_7); // Skywire Send |
kholland | 10:5974a7b2cf38 | 83 | DigitalOut green_LED(PA_1); // Green LED |
kholland | 10:5974a7b2cf38 | 84 | DigitalOut red_LED(PA_4); // Red LED |
kholland | 10:5974a7b2cf38 | 85 | DigitalOut blue_LED(PB_0); // Blue LED |
kholland | 0:3095958bc639 | 86 | |
kholland | 10:5974a7b2cf38 | 87 | AnalogIn photo_trans(PA_0); // Photo Transistor |
kholland | 10:5974a7b2cf38 | 88 | AnalogIn pot(PC_0); // Potentiometer |
kholland | 10:5974a7b2cf38 | 89 | DigitalIn button1(PB_3); // Button 1 |
kholland | 10:5974a7b2cf38 | 90 | DigitalIn button2(PC_1); // Button 2 |
kholland | 10:5974a7b2cf38 | 91 | |
kholland | 10:5974a7b2cf38 | 92 | Serial skywire(PA_9,PA_10); // Serial comms to Skywire |
kholland | 10:5974a7b2cf38 | 93 | Serial debug_pc(USBTX, USBRX); // USB connection to PC |
kholland | 10:5974a7b2cf38 | 94 | |
kholland | 10:5974a7b2cf38 | 95 | I2C i2c(PB_9,PB_8); // Setup I2C bus for sensors |
kholland | 10:5974a7b2cf38 | 96 | bool sw1; // Boolean to check if button 1 is pressed |
kholland | 10:5974a7b2cf38 | 97 | bool sw2; // Boolean to check if button 2 is pressed |
kholland | 10:5974a7b2cf38 | 98 | |
kholland | 10:5974a7b2cf38 | 99 | LPS331 pressure(i2c); // Pressure Sensor |
kholland | 10:5974a7b2cf38 | 100 | LM75B LM75_temp(PB_9,PB_8); // Temp Sensor |
kholland | 10:5974a7b2cf38 | 101 | // Accelerometer |
kholland | 0:3095958bc639 | 102 | LIS3DH accel(i2c, LIS3DH_V_CHIP_ADDR, LIS3DH_DR_NR_LP_100HZ, LIS3DH_FS_2G); |
kholland | 10:5974a7b2cf38 | 103 | HTS221 humidity(PB_9, PB_8); // Humidity Sensor |
kholland | 0:3095958bc639 | 104 | |
kholland | 10:5974a7b2cf38 | 105 | // char array for reading from Skywire |
kholland | 3:4b2176f6474c | 106 | char str[255]; |
kholland | 3:4b2176f6474c | 107 | |
kholland | 10:5974a7b2cf38 | 108 | // Variables for GPS |
kholland | 0:3095958bc639 | 109 | float latitude; |
kholland | 0:3095958bc639 | 110 | float longitude; |
kholland | 0:3095958bc639 | 111 | int number; |
kholland | 0:3095958bc639 | 112 | |
kholland | 10:5974a7b2cf38 | 113 | // Variables for UART comms |
kholland | 3:4b2176f6474c | 114 | volatile int rx_in=0; |
kholland | 3:4b2176f6474c | 115 | volatile int rx_out=0; |
kholland | 10:5974a7b2cf38 | 116 | const int buffer_size = 600; |
kholland | 3:4b2176f6474c | 117 | char rx_buffer[buffer_size+1]; |
kholland | 3:4b2176f6474c | 118 | char rx_line[buffer_size]; |
kholland | 3:4b2176f6474c | 119 | |
kholland | 10:5974a7b2cf38 | 120 | // Interrupt for the Skywire |
kholland | 10:5974a7b2cf38 | 121 | void Skywire_Rx_interrupt() |
kholland | 10:5974a7b2cf38 | 122 | { |
kholland | 3:4b2176f6474c | 123 | // Loop just in case more than one character is in UART's receive FIFO buffer |
kholland | 3:4b2176f6474c | 124 | // Stop if buffer full |
kholland | 3:4b2176f6474c | 125 | while ((skywire.readable()) && (((rx_in + 1) % buffer_size) != rx_out)) { |
kholland | 3:4b2176f6474c | 126 | rx_buffer[rx_in] = skywire.getc(); |
kholland | 3:4b2176f6474c | 127 | rx_in = (rx_in + 1) % buffer_size; |
kholland | 3:4b2176f6474c | 128 | } |
kholland | 3:4b2176f6474c | 129 | return; |
kholland | 3:4b2176f6474c | 130 | } |
kholland | 3:4b2176f6474c | 131 | |
kholland | 10:5974a7b2cf38 | 132 | // Function to blink LEDs for debugging |
kholland | 10:5974a7b2cf38 | 133 | // NOTE: Currently not used |
kholland | 10:5974a7b2cf38 | 134 | void blink_leds(int num) |
kholland | 10:5974a7b2cf38 | 135 | { |
kholland | 10:5974a7b2cf38 | 136 | for (int i = 0; i < num; i++) { |
kholland | 10:5974a7b2cf38 | 137 | blue_LED = 0; |
kholland | 10:5974a7b2cf38 | 138 | wait(0.5); |
kholland | 10:5974a7b2cf38 | 139 | blue_LED = 1; |
kholland | 10:5974a7b2cf38 | 140 | wait(0.5); |
kholland | 10:5974a7b2cf38 | 141 | } |
kholland | 10:5974a7b2cf38 | 142 | } |
kholland | 10:5974a7b2cf38 | 143 | |
kholland | 10:5974a7b2cf38 | 144 | // Read line from the UART |
kholland | 10:5974a7b2cf38 | 145 | void read_line() |
kholland | 10:5974a7b2cf38 | 146 | { |
kholland | 3:4b2176f6474c | 147 | int i; |
kholland | 3:4b2176f6474c | 148 | i = 0; |
kholland | 3:4b2176f6474c | 149 | // Start Critical Section - don't interrupt while changing global buffer variables |
kholland | 3:4b2176f6474c | 150 | __disable_irq(); |
kholland | 3:4b2176f6474c | 151 | // Loop reading rx buffer characters until end of line character |
kholland | 3:4b2176f6474c | 152 | while ((i==0) || (rx_line[i-1] != '\n')) { |
kholland | 3:4b2176f6474c | 153 | // Wait if buffer empty |
kholland | 3:4b2176f6474c | 154 | if (rx_in == rx_out) { |
kholland | 3:4b2176f6474c | 155 | // End Critical Section - need to allow rx interrupt to get new characters for buffer |
kholland | 3:4b2176f6474c | 156 | __enable_irq(); |
kholland | 3:4b2176f6474c | 157 | while (rx_in == rx_out) { |
kholland | 3:4b2176f6474c | 158 | } |
kholland | 3:4b2176f6474c | 159 | // Start Critical Section - don't interrupt while changing global buffer variables |
kholland | 3:4b2176f6474c | 160 | __disable_irq(); |
kholland | 3:4b2176f6474c | 161 | } |
kholland | 3:4b2176f6474c | 162 | rx_line[i] = rx_buffer[rx_out]; |
kholland | 3:4b2176f6474c | 163 | i++; |
kholland | 3:4b2176f6474c | 164 | rx_out = (rx_out + 1) % buffer_size; |
kholland | 3:4b2176f6474c | 165 | } |
kholland | 3:4b2176f6474c | 166 | // End Critical Section |
kholland | 3:4b2176f6474c | 167 | __enable_irq(); |
kholland | 3:4b2176f6474c | 168 | rx_line[i-1] = 0; |
kholland | 3:4b2176f6474c | 169 | return; |
kholland | 3:4b2176f6474c | 170 | } |
kholland | 10:5974a7b2cf38 | 171 | |
kholland | 10:5974a7b2cf38 | 172 | // Wait for specific response |
kholland | 10:5974a7b2cf38 | 173 | int WaitForResponse(char* response, int num) |
kholland | 10:5974a7b2cf38 | 174 | { |
kholland | 3:4b2176f6474c | 175 | do { |
kholland | 3:4b2176f6474c | 176 | read_line(); |
kholland | 3:4b2176f6474c | 177 | debug_pc.printf("Waiting for: %s, Recieved: %s\r\n", response, rx_line); |
kholland | 3:4b2176f6474c | 178 | } while (strncmp(rx_line, response, num)); |
kholland | 3:4b2176f6474c | 179 | return 0; |
kholland | 3:4b2176f6474c | 180 | } |
kholland | 10:5974a7b2cf38 | 181 | |
kholland | 10:5974a7b2cf38 | 182 | int main() |
kholland | 0:3095958bc639 | 183 | { |
kholland | 0:3095958bc639 | 184 | float axis[3]; |
kholland | 0:3095958bc639 | 185 | float press; |
kholland | 0:3095958bc639 | 186 | float temp; |
kylerodgers | 7:00d66e743603 | 187 | float humi; |
kylerodgers | 7:00d66e743603 | 188 | float dummy_temp; |
kholland | 0:3095958bc639 | 189 | |
kholland | 10:5974a7b2cf38 | 190 | // Setup serial comms with Skywire and PC |
kholland | 0:3095958bc639 | 191 | debug_pc.baud(115200); |
kholland | 0:3095958bc639 | 192 | skywire.baud(115200); |
kholland | 10:5974a7b2cf38 | 193 | debug_pc.printf("SystemCoreClock = %d Hz\r\n", SystemCoreClock); |
kholland | 3:4b2176f6474c | 194 | skywire.attach(&Skywire_Rx_interrupt, Serial::RxIrq); |
kholland | 10:5974a7b2cf38 | 195 | |
kholland | 10:5974a7b2cf38 | 196 | // Turn on blue LED |
kholland | 10:5974a7b2cf38 | 197 | green_LED = 0; |
kholland | 10:5974a7b2cf38 | 198 | red_LED = 0; |
kholland | 10:5974a7b2cf38 | 199 | blue_LED = 1; |
kholland | 10:5974a7b2cf38 | 200 | |
kholland | 0:3095958bc639 | 201 | skywire_rts=0; |
kholland | 0:3095958bc639 | 202 | myled=0; |
kholland | 3:4b2176f6474c | 203 | debug_pc.printf("Starting Demo...\r\n"); |
kholland | 3:4b2176f6474c | 204 | debug_pc.printf("Waiting for Skywire to Boot...\r\n"); |
kholland | 10:5974a7b2cf38 | 205 | |
kholland | 0:3095958bc639 | 206 | //Enable Skywire |
kholland | 0:3095958bc639 | 207 | skywire_en=0; |
kholland | 0:3095958bc639 | 208 | wait(2); |
kholland | 0:3095958bc639 | 209 | skywire_en=1; |
kholland | 0:3095958bc639 | 210 | wait(2); |
kholland | 0:3095958bc639 | 211 | skywire_en=0; |
kholland | 3:4b2176f6474c | 212 | |
kholland | 3:4b2176f6474c | 213 | myled=1; |
kholland | 3:4b2176f6474c | 214 | |
kholland | 10:5974a7b2cf38 | 215 | // Wait for modem to initialize |
kholland | 10:5974a7b2cf38 | 216 | // Wait time is different for each modem |
kholland | 10:5974a7b2cf38 | 217 | #if defined NL_SW_LTE_GELS3 |
kholland | 10:5974a7b2cf38 | 218 | wait(60); |
kholland | 10:5974a7b2cf38 | 219 | #elif defined NL_SW_LTE_TSVG || defined NL_SW_LTE_TNAG || defined NL_SW_LTE_TEUG |
kholland | 10:5974a7b2cf38 | 220 | wait(15); |
kholland | 10:5974a7b2cf38 | 221 | #else |
kholland | 10:5974a7b2cf38 | 222 | wait(5); |
kholland | 10:5974a7b2cf38 | 223 | #endif |
kholland | 10:5974a7b2cf38 | 224 | |
kholland | 10:5974a7b2cf38 | 225 | // Start temp reading |
kholland | 3:4b2176f6474c | 226 | LM75_temp.open(); |
kholland | 10:5974a7b2cf38 | 227 | |
kholland | 3:4b2176f6474c | 228 | //Turn off echo |
kholland | 10:5974a7b2cf38 | 229 | // Helps with checking responses from Skywire |
kholland | 10:5974a7b2cf38 | 230 | debug_pc.printf("Turning off echo...\r\n"); |
kholland | 3:4b2176f6474c | 231 | skywire.printf("ATE0\r\n"); |
kholland | 3:4b2176f6474c | 232 | WaitForResponse("OK", 2); |
kholland | 10:5974a7b2cf38 | 233 | |
kholland | 10:5974a7b2cf38 | 234 | // Turn on DNS Response Caching |
kholland | 10:5974a7b2cf38 | 235 | // Used on the Telit-based Skywires |
kholland | 10:5974a7b2cf38 | 236 | #if !defined NL_SW_LTE_GELS3 |
kholland | 10:5974a7b2cf38 | 237 | debug_pc.printf("Turning on DNS Cacheing to improve speed..."); |
kholland | 10:5974a7b2cf38 | 238 | skywire.printf("AT#CACHEDNS=1\r\n"); |
kholland | 10:5974a7b2cf38 | 239 | WaitForResponse("OK", 2); |
kholland | 10:5974a7b2cf38 | 240 | #endif |
kholland | 10:5974a7b2cf38 | 241 | |
kholland | 3:4b2176f6474c | 242 | debug_pc.printf("Connecting to Network...\r\n"); |
kholland | 0:3095958bc639 | 243 | // get IP address |
kholland | 10:5974a7b2cf38 | 244 | #if defined NL_SW_LTE_GELS3 |
kholland | 10:5974a7b2cf38 | 245 | // The last parameter in AT+SQNSCFG sets the timeout if transmit buffer is not full |
kholland | 10:5974a7b2cf38 | 246 | // Time is in hundreds of ms: so, a value of 5 = 500ms |
kholland | 10:5974a7b2cf38 | 247 | debug_pc.printf("Configuring context part 1...\r\n"); |
kholland | 10:5974a7b2cf38 | 248 | skywire.printf("AT+SQNSCFG=3,3,300,90,600,5\r\n"); |
kholland | 10:5974a7b2cf38 | 249 | WaitForResponse("OK", 2); |
kholland | 10:5974a7b2cf38 | 250 | wait(1); |
kholland | 10:5974a7b2cf38 | 251 | debug_pc.printf("Configuring context part 2...\r\n"); |
kholland | 10:5974a7b2cf38 | 252 | skywire.printf("AT+CGDCONT=3,\"IP\",\"vzwinternet\"\r\n"); |
kholland | 10:5974a7b2cf38 | 253 | WaitForResponse("OK", 2); |
kholland | 10:5974a7b2cf38 | 254 | wait(1); |
kholland | 10:5974a7b2cf38 | 255 | debug_pc.printf("Activating context...\r\n"); |
kholland | 10:5974a7b2cf38 | 256 | skywire.printf("AT+CGACT=1,3\r\n"); |
kholland | 10:5974a7b2cf38 | 257 | #elif defined NL_SW_LTE_TSVG |
kholland | 10:5974a7b2cf38 | 258 | // The last parameter in AT#SCFG sets the timeout if transmit buffer is not full |
kholland | 10:5974a7b2cf38 | 259 | // Time is in hundreds of ms: so, a value of 5 = 500 ms |
kholland | 10:5974a7b2cf38 | 260 | skywire.printf("AT#SCFG=3,3,300,90,600,5\r\n"); |
kholland | 10:5974a7b2cf38 | 261 | WaitForResponse("OK", 2); |
kholland | 10:5974a7b2cf38 | 262 | wait(1); |
kholland | 10:5974a7b2cf38 | 263 | skywire.printf("AT+CGDCONT=3,\"IP\",\"%s\"\r\n", APN); |
kholland | 10:5974a7b2cf38 | 264 | WaitForResponse("OK", 2); |
kholland | 10:5974a7b2cf38 | 265 | wait(1); |
kholland | 10:5974a7b2cf38 | 266 | skywire.printf("AT#SGACT=3,1\r\n"); |
kholland | 10:5974a7b2cf38 | 267 | WaitForResponse("#SGACT", 6); |
kholland | 10:5974a7b2cf38 | 268 | #else |
kholland | 10:5974a7b2cf38 | 269 | // The last parameter in AT#SCFG sets the timeout if transmit buffer is not full |
kholland | 10:5974a7b2cf38 | 270 | // Time is in hundreds of ms: so, a value of 5 = 500 ms |
kholland | 10:5974a7b2cf38 | 271 | skywire.printf("AT#SCFG=1,1,300,90,600,5\r\n"); |
kholland | 10:5974a7b2cf38 | 272 | WaitForResponse("OK", 2); |
kholland | 10:5974a7b2cf38 | 273 | skywire.printf("AT#SGACT=1,1\r\n"); |
kholland | 10:5974a7b2cf38 | 274 | WaitForResponse("#SGACT", 6); |
kholland | 10:5974a7b2cf38 | 275 | #endif |
kholland | 3:4b2176f6474c | 276 | WaitForResponse("OK", 2); |
kylerodgers | 7:00d66e743603 | 277 | |
kholland | 10:5974a7b2cf38 | 278 | // Get triangulation data |
kholland | 10:5974a7b2cf38 | 279 | // NOTE: This only works on the below modems! |
kholland | 10:5974a7b2cf38 | 280 | #if defined NL_SW_1xRTT_V || defined NL_SW_1xRTT_S || defined NL_SW_1xRTT_A || defined NL_SW_GPRS || defined NL_SW_EVDO_V || defined NL_SW_EVDO_A || defined NL_SW_HSPAP || defined NL_SW_HSPAPG || defined NL_SW_HSPAPE |
kholland | 10:5974a7b2cf38 | 281 | //get location approximation from cell tower information |
kholland | 10:5974a7b2cf38 | 282 | skywire.printf("AT#AGPSSND\r\n"); |
kholland | 10:5974a7b2cf38 | 283 | WaitForResponse("#AGPSRING:", 10); |
kholland | 10:5974a7b2cf38 | 284 | sscanf(rx_line, "%s %d,%f,%f,", str, &number, &latitude, &longitude); |
kholland | 10:5974a7b2cf38 | 285 | debug_pc.printf("Location: Latt:%f, Long:%f\r\n", latitude, longitude); |
kholland | 10:5974a7b2cf38 | 286 | #endif |
kholland | 10:5974a7b2cf38 | 287 | |
kholland | 10:5974a7b2cf38 | 288 | red_LED = 0; |
kholland | 10:5974a7b2cf38 | 289 | blue_LED = 0; |
kholland | 10:5974a7b2cf38 | 290 | green_LED = 1; |
kholland | 3:4b2176f6474c | 291 | |
kholland | 0:3095958bc639 | 292 | while(1) { |
kholland | 10:5974a7b2cf38 | 293 | // Green on to indicate code position |
kholland | 10:5974a7b2cf38 | 294 | // Start of loop. Either entered loop for the first time or just sent to dweet.io |
kholland | 10:5974a7b2cf38 | 295 | red_LED = 0; |
kholland | 10:5974a7b2cf38 | 296 | blue_LED = 0; |
kholland | 10:5974a7b2cf38 | 297 | green_LED = 1; |
kholland | 10:5974a7b2cf38 | 298 | // connect to dweet.io |
kholland | 10:5974a7b2cf38 | 299 | #if defined NL_SW_LTE_GELS3 |
kholland | 10:5974a7b2cf38 | 300 | skywire.printf("AT+SQNSD=3,0,80,\"dweet.io\"\r\n"); |
kholland | 10:5974a7b2cf38 | 301 | #elif defined NL_SW_LTE_TSVG |
kholland | 10:5974a7b2cf38 | 302 | skywire.printf("AT#SD=3,0,80,\"dweet.io\"\r\n"); |
kholland | 10:5974a7b2cf38 | 303 | #else |
kholland | 10:5974a7b2cf38 | 304 | skywire.printf("AT#SD=1,0,80,\"dweet.io\"\r\n"); |
kholland | 10:5974a7b2cf38 | 305 | #endif |
kholland | 10:5974a7b2cf38 | 306 | WaitForResponse("CONNECT", 7); |
kholland | 10:5974a7b2cf38 | 307 | |
kholland | 10:5974a7b2cf38 | 308 | |
kholland | 10:5974a7b2cf38 | 309 | // Update the sensors |
kholland | 0:3095958bc639 | 310 | temp = (float)LM75_temp; |
kholland | 10:5974a7b2cf38 | 311 | //temp = (temp * 9)/5 + 32; // convert C to F |
kholland | 3:4b2176f6474c | 312 | debug_pc.printf("Temp = %.3f\r\n", temp); |
kholland | 0:3095958bc639 | 313 | press=(float)pressure.value() / 4096; |
kholland | 3:4b2176f6474c | 314 | debug_pc.printf("Pressure = %.3f\r\n", press); |
kylerodgers | 7:00d66e743603 | 315 | humidity.ReadTempHumi(&dummy_temp, &humi); |
kylerodgers | 7:00d66e743603 | 316 | debug_pc.printf("Humidity = %.3f\r\n", humi); |
kholland | 0:3095958bc639 | 317 | accel.read_data(axis); |
kholland | 3:4b2176f6474c | 318 | debug_pc.printf("Accel = %.3f, %.3f, %.3f\r\n", axis[0], axis[1], axis[2]); |
kholland | 10:5974a7b2cf38 | 319 | |
kholland | 10:5974a7b2cf38 | 320 | wait(1); |
kholland | 10:5974a7b2cf38 | 321 | |
kholland | 10:5974a7b2cf38 | 322 | // Check buttons for presses |
kholland | 10:5974a7b2cf38 | 323 | if (button1 == 0) |
kholland | 10:5974a7b2cf38 | 324 | sw1 = 0; |
kholland | 10:5974a7b2cf38 | 325 | else |
kholland | 10:5974a7b2cf38 | 326 | sw1 = 1; |
kholland | 10:5974a7b2cf38 | 327 | if (button2 == 0) |
kholland | 10:5974a7b2cf38 | 328 | sw2 = 0; |
kholland | 10:5974a7b2cf38 | 329 | else |
kholland | 10:5974a7b2cf38 | 330 | sw2 = 1; |
kholland | 3:4b2176f6474c | 331 | |
kholland | 10:5974a7b2cf38 | 332 | // Green on to indicate code position: |
kholland | 10:5974a7b2cf38 | 333 | // Sensors updated, have not sent to dweet.io |
kholland | 10:5974a7b2cf38 | 334 | red_LED = 1; |
kholland | 10:5974a7b2cf38 | 335 | green_LED = 0; |
kholland | 10:5974a7b2cf38 | 336 | blue_LED = 0; |
kholland | 10:5974a7b2cf38 | 337 | |
kholland | 10:5974a7b2cf38 | 338 | debug_pc.printf("Sending information...\r\n"); |
kholland | 10:5974a7b2cf38 | 339 | // Report the sensor data to dweet.io |
kholland | 10:5974a7b2cf38 | 340 | skywire.printf("POST /dweet/for/%s?temp=%.3f&p=%.3f&X=%.3f&Y=%.3f&Z=%.3f&La=%f&Lo=%f&sw1=%d&sw2=%d&pot=%.3f&photo=%.3f&humidity=%.3f HTTP/1.0\r\n\r\n", DeviceID, temp, press, axis[0], axis[1], axis[2], latitude, longitude, sw1, sw2, (pot * 3), (photo_trans * 100), humi); |
kholland | 10:5974a7b2cf38 | 341 | |
kholland | 10:5974a7b2cf38 | 342 | // Blue on to indicate code position |
kholland | 10:5974a7b2cf38 | 343 | // Data sent to dweet |
kholland | 10:5974a7b2cf38 | 344 | red_LED = 0; |
kholland | 10:5974a7b2cf38 | 345 | green_LED = 0; |
kholland | 10:5974a7b2cf38 | 346 | blue_LED = 1; |
kholland | 10:5974a7b2cf38 | 347 | |
kholland | 10:5974a7b2cf38 | 348 | // Wait for response from dweet.io |
kholland | 10:5974a7b2cf38 | 349 | #if defined NL_SW_LTE_GELS3 |
kholland | 10:5974a7b2cf38 | 350 | WaitForResponse("OK", 2); |
kholland | 10:5974a7b2cf38 | 351 | wait(1); |
kholland | 10:5974a7b2cf38 | 352 | #else |
kholland | 10:5974a7b2cf38 | 353 | WaitForResponse("NO CARRIER", 10); |
kholland | 10:5974a7b2cf38 | 354 | #endif |
kholland | 3:4b2176f6474c | 355 | } |
kholland | 10:5974a7b2cf38 | 356 | } |