
Release 1.0 supporting the Kinetis Freedom K64F board and NimbeLink NL-AB-ST-NCL and NimbeLink NL-SWSK. Tested with NL-SW-1xRTT-V and NL-SW-EVDO-V modems.
Dependencies: LIS3DH LM75B LPS331 mbed hts221
Getting Started Guide
Note for the NL-AB-ST-NCL: In order to use the NimbeLink NL-AB-ST-NCL with the NXP FRDM-K64F, you must populate Resistors R2 and R8 while removing resistors R1 and R7. The NimbeLink NL-AB-ST-NCL will not work with the FRDM-K64F unless this change is made.
Note for the NL-SWSK: In order to use the NimbeLink NL-SWSK with the NXP FRDM-K64F, you must move Jumpers J3 and J4 to pins 2 and 3. The NimbeLink NL-SWSK will not work with the FRDM-K64F unless this change is made.
- Place the Skywire Shield onto the FRDM-K64F as pictured
- Place the Skywire modem onto the Shield as picture and attach the antenna U.FL coax cable as pictured
- Screw in the antenna
- Plug the 12V wall supply into the Skywire Shield
- For serial debugging, plug a micro-USB cable into port J26 of the FRDM-K64F. If you are using Windows, make sure you have the serial drivers installed-please consult the guide at https://developer.mbed.org/handbook/Windows-serial-configuration for installation.Use a terminal emulation program such as TeraTerm with the following settings:
- Baud Rate: 115200
- Data: 8 bit
- Parity: none
- Stop: 1 bit
- Flow Control: none
- Go to https://freeboard.io/ and create a user account
- Once you are logged into your Freeboard account, go to https://freeboard.io/board/LhnbrX and clone the dashboard by clicking the CLONE link in the lower right corner
- Old revision of dashboard is available here: https://freeboard.io/board/jqlneI
- Old revision of dashboard is available here: https://freeboard.io/board/jqlneI
- The new dashboard will show up on you account list under My Freeboards, you can then edit the name to whatever you like
- Under the Datasources tab on the dashboard, click the skywire link
- Change the THING NAME field to the MEID of the Skywire Modem. The MEID is printed on top of the modem. Otherwise, you can get the MEID from the serial output.
- Next Import the Skywire_Kinetis_K64_demo program into the online compiler
- Compile and upload to the FRDM-K64F, cycle power to the shield and the sensor data should start to upload to your new Freeboard.
main.cpp@1:e05da6207ebb, 2015-08-12 (annotated)
- Committer:
- kylerodgers
- Date:
- Wed Aug 12 15:55:43 2015 +0000
- Revision:
- 1:e05da6207ebb
- Parent:
- 0:a096c02fb1b0
Added humidity sensor information
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kylerodgers | 1:e05da6207ebb | 1 | /* main.cpp */ |
kylerodgers | 1:e05da6207ebb | 2 | /* v1.1 |
kylerodgers | 1:e05da6207ebb | 3 | * Copyright (C) 2015 nimbelink.com, MIT License |
kylerodgers | 1:e05da6207ebb | 4 | * |
kylerodgers | 1:e05da6207ebb | 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
kylerodgers | 1:e05da6207ebb | 6 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
kylerodgers | 1:e05da6207ebb | 7 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
kylerodgers | 1:e05da6207ebb | 8 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
kylerodgers | 1:e05da6207ebb | 9 | * furnished to do so, subject to the following conditions: |
kylerodgers | 1:e05da6207ebb | 10 | * |
kylerodgers | 1:e05da6207ebb | 11 | * The above copyright notice and this permission notice shall be included in all copies or |
kylerodgers | 1:e05da6207ebb | 12 | * substantial portions of the Software. |
kylerodgers | 1:e05da6207ebb | 13 | * |
kylerodgers | 1:e05da6207ebb | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
kylerodgers | 1:e05da6207ebb | 15 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
kylerodgers | 1:e05da6207ebb | 16 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
kylerodgers | 1:e05da6207ebb | 17 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
kylerodgers | 1:e05da6207ebb | 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
kylerodgers | 1:e05da6207ebb | 19 | */ |
kylerodgers | 1:e05da6207ebb | 20 | |
KurtDiver | 0:a096c02fb1b0 | 21 | #include "mbed.h" |
KurtDiver | 0:a096c02fb1b0 | 22 | #include "LPS331.h" |
KurtDiver | 0:a096c02fb1b0 | 23 | #include "LIS3DH.h" |
KurtDiver | 0:a096c02fb1b0 | 24 | #include "LM75B.h" |
kylerodgers | 1:e05da6207ebb | 25 | #include "hts221.h" |
KurtDiver | 0:a096c02fb1b0 | 26 | |
KurtDiver | 0:a096c02fb1b0 | 27 | // #define DeviceID "A100003E4226B3" //Freeboard DweetIO unique ID |
KurtDiver | 0:a096c02fb1b0 | 28 | // dynamically assigning this based on modem's unique identifier below |
KurtDiver | 0:a096c02fb1b0 | 29 | char DeviceID[15]; |
KurtDiver | 0:a096c02fb1b0 | 30 | |
KurtDiver | 0:a096c02fb1b0 | 31 | |
KurtDiver | 0:a096c02fb1b0 | 32 | DigitalOut skywire_en(PTD3); //K64 FRDM |
KurtDiver | 0:a096c02fb1b0 | 33 | DigitalOut skywire_rts(PTD2); //K64 FRDM |
KurtDiver | 0:a096c02fb1b0 | 34 | DigitalOut skywire_dtr(PTD0); //K64 FRDM |
KurtDiver | 0:a096c02fb1b0 | 35 | |
KurtDiver | 0:a096c02fb1b0 | 36 | DigitalOut led_red(LED_RED); |
KurtDiver | 0:a096c02fb1b0 | 37 | DigitalOut led_green(LED_GREEN); |
KurtDiver | 0:a096c02fb1b0 | 38 | DigitalIn sw2(SW2); |
KurtDiver | 0:a096c02fb1b0 | 39 | DigitalIn sw3(SW3); |
KurtDiver | 0:a096c02fb1b0 | 40 | Serial pc(USBTX, USBRX); |
KurtDiver | 0:a096c02fb1b0 | 41 | Serial skywire(PTC17, PTC16); //K64 FRDM |
KurtDiver | 0:a096c02fb1b0 | 42 | |
KurtDiver | 0:a096c02fb1b0 | 43 | I2C i2c(PTE25,PTE24); |
KurtDiver | 0:a096c02fb1b0 | 44 | char msg[3]; |
KurtDiver | 0:a096c02fb1b0 | 45 | |
KurtDiver | 0:a096c02fb1b0 | 46 | LPS331 pressure(i2c); |
KurtDiver | 0:a096c02fb1b0 | 47 | LM75B LM75_temp(PTE25,PTE24); |
KurtDiver | 0:a096c02fb1b0 | 48 | LIS3DH accel(i2c, LIS3DH_V_CHIP_ADDR, LIS3DH_DR_NR_LP_100HZ, LIS3DH_FS_2G); |
kylerodgers | 1:e05da6207ebb | 49 | HTS221 humidity(PTE25, PTE24); |
KurtDiver | 0:a096c02fb1b0 | 50 | |
KurtDiver | 0:a096c02fb1b0 | 51 | char str[255]; |
KurtDiver | 0:a096c02fb1b0 | 52 | |
KurtDiver | 0:a096c02fb1b0 | 53 | float latitude; |
KurtDiver | 0:a096c02fb1b0 | 54 | float longitude; |
KurtDiver | 0:a096c02fb1b0 | 55 | int number; |
KurtDiver | 0:a096c02fb1b0 | 56 | |
KurtDiver | 0:a096c02fb1b0 | 57 | volatile int rx_in=0; |
KurtDiver | 0:a096c02fb1b0 | 58 | volatile int rx_out=0; |
KurtDiver | 0:a096c02fb1b0 | 59 | const int buffer_size = 255; |
KurtDiver | 0:a096c02fb1b0 | 60 | char rx_buffer[buffer_size+1]; |
KurtDiver | 0:a096c02fb1b0 | 61 | |
KurtDiver | 0:a096c02fb1b0 | 62 | char rx_line[buffer_size]; |
KurtDiver | 0:a096c02fb1b0 | 63 | |
KurtDiver | 0:a096c02fb1b0 | 64 | void Skywire_Rx_interrupt() { |
KurtDiver | 0:a096c02fb1b0 | 65 | // Loop just in case more than one character is in UART's receive FIFO buffer |
KurtDiver | 0:a096c02fb1b0 | 66 | // Stop if buffer full |
KurtDiver | 0:a096c02fb1b0 | 67 | while ((skywire.readable()) && (((rx_in + 1) % buffer_size) != rx_out)) { |
KurtDiver | 0:a096c02fb1b0 | 68 | rx_buffer[rx_in] = skywire.getc(); |
KurtDiver | 0:a096c02fb1b0 | 69 | rx_in = (rx_in + 1) % buffer_size; |
KurtDiver | 0:a096c02fb1b0 | 70 | } |
KurtDiver | 0:a096c02fb1b0 | 71 | return; |
KurtDiver | 0:a096c02fb1b0 | 72 | } |
KurtDiver | 0:a096c02fb1b0 | 73 | |
KurtDiver | 0:a096c02fb1b0 | 74 | void read_line() { |
KurtDiver | 0:a096c02fb1b0 | 75 | int i; |
KurtDiver | 0:a096c02fb1b0 | 76 | i = 0; |
KurtDiver | 0:a096c02fb1b0 | 77 | // Start Critical Section - don't interrupt while changing global buffer variables |
KurtDiver | 0:a096c02fb1b0 | 78 | __disable_irq(); |
KurtDiver | 0:a096c02fb1b0 | 79 | // Loop reading rx buffer characters until end of line character |
KurtDiver | 0:a096c02fb1b0 | 80 | while ((i==0) || (rx_line[i-1] != '\n')) { |
KurtDiver | 0:a096c02fb1b0 | 81 | // Wait if buffer empty |
KurtDiver | 0:a096c02fb1b0 | 82 | if (rx_in == rx_out) { |
KurtDiver | 0:a096c02fb1b0 | 83 | // End Critical Section - need to allow rx interrupt to get new characters for buffer |
KurtDiver | 0:a096c02fb1b0 | 84 | __enable_irq(); |
KurtDiver | 0:a096c02fb1b0 | 85 | while (rx_in == rx_out) { |
KurtDiver | 0:a096c02fb1b0 | 86 | //pc.printf("..Read_line entered2.5\r\n"); |
KurtDiver | 0:a096c02fb1b0 | 87 | } |
KurtDiver | 0:a096c02fb1b0 | 88 | // Start Critical Section - don't interrupt while changing global buffer variables |
KurtDiver | 0:a096c02fb1b0 | 89 | __disable_irq(); |
KurtDiver | 0:a096c02fb1b0 | 90 | } |
KurtDiver | 0:a096c02fb1b0 | 91 | rx_line[i] = rx_buffer[rx_out]; |
KurtDiver | 0:a096c02fb1b0 | 92 | i++; |
KurtDiver | 0:a096c02fb1b0 | 93 | rx_out = (rx_out + 1) % buffer_size; |
KurtDiver | 0:a096c02fb1b0 | 94 | } |
KurtDiver | 0:a096c02fb1b0 | 95 | // End Critical Section |
KurtDiver | 0:a096c02fb1b0 | 96 | __enable_irq(); |
KurtDiver | 0:a096c02fb1b0 | 97 | rx_line[i-1] = 0; |
KurtDiver | 0:a096c02fb1b0 | 98 | return; |
KurtDiver | 0:a096c02fb1b0 | 99 | } |
KurtDiver | 0:a096c02fb1b0 | 100 | int WaitForResponse(char* response, int num) { |
KurtDiver | 0:a096c02fb1b0 | 101 | do { |
KurtDiver | 0:a096c02fb1b0 | 102 | read_line(); |
KurtDiver | 0:a096c02fb1b0 | 103 | pc.printf("Waiting for: %s, Recieved: %s\r\n", response, rx_line); |
KurtDiver | 0:a096c02fb1b0 | 104 | } while (strncmp(rx_line, response, num)); |
KurtDiver | 0:a096c02fb1b0 | 105 | return 0; |
KurtDiver | 0:a096c02fb1b0 | 106 | } |
KurtDiver | 0:a096c02fb1b0 | 107 | |
KurtDiver | 0:a096c02fb1b0 | 108 | void check_sw2(void) |
KurtDiver | 0:a096c02fb1b0 | 109 | { |
KurtDiver | 0:a096c02fb1b0 | 110 | if (sw2 == 0) { |
KurtDiver | 0:a096c02fb1b0 | 111 | pc.printf("SW2 button pressed. \r\n"); |
KurtDiver | 0:a096c02fb1b0 | 112 | // turn RED LED on to indicate provisioning process has started |
KurtDiver | 0:a096c02fb1b0 | 113 | led_red = 0; |
KurtDiver | 0:a096c02fb1b0 | 114 | led_green = 1; |
KurtDiver | 0:a096c02fb1b0 | 115 | wait(1); |
KurtDiver | 0:a096c02fb1b0 | 116 | // turn LEDs off |
KurtDiver | 0:a096c02fb1b0 | 117 | led_red = 1; |
KurtDiver | 0:a096c02fb1b0 | 118 | led_green = 1; |
KurtDiver | 0:a096c02fb1b0 | 119 | skywire.printf("ATD*22899;\r\n"); |
KurtDiver | 0:a096c02fb1b0 | 120 | WaitForResponse("#OTASP: 0", 9); |
KurtDiver | 0:a096c02fb1b0 | 121 | pc.printf("Provisioning: #OTASP: 0 reached. \r\n"); |
KurtDiver | 0:a096c02fb1b0 | 122 | // turn RED LED on |
KurtDiver | 0:a096c02fb1b0 | 123 | led_red = 0; |
KurtDiver | 0:a096c02fb1b0 | 124 | led_green = 1; |
KurtDiver | 0:a096c02fb1b0 | 125 | WaitForResponse("#OTASP: 1", 9); |
KurtDiver | 0:a096c02fb1b0 | 126 | pc.printf("Provisioning: #OTASP: 1 reached. \r\n"); |
KurtDiver | 0:a096c02fb1b0 | 127 | // turn both LEDs on |
KurtDiver | 0:a096c02fb1b0 | 128 | led_red = 0; |
KurtDiver | 0:a096c02fb1b0 | 129 | led_green = 0; |
KurtDiver | 0:a096c02fb1b0 | 130 | WaitForResponse("#OTASP: 2", 9); |
KurtDiver | 0:a096c02fb1b0 | 131 | pc.printf("Provisioning: #OTASP: 2 reached. \r\n"); |
KurtDiver | 0:a096c02fb1b0 | 132 | // turn GREEN LED on |
KurtDiver | 0:a096c02fb1b0 | 133 | led_red = 1; |
KurtDiver | 0:a096c02fb1b0 | 134 | led_green = 0; |
KurtDiver | 0:a096c02fb1b0 | 135 | WaitForResponse("NO CARRIER", 10); |
KurtDiver | 0:a096c02fb1b0 | 136 | pc.printf("Provisioning successfully completed. \r\n"); |
KurtDiver | 0:a096c02fb1b0 | 137 | |
KurtDiver | 0:a096c02fb1b0 | 138 | skywire.printf("AT#REBOOT"); |
KurtDiver | 0:a096c02fb1b0 | 139 | // wait 10 seconds |
KurtDiver | 0:a096c02fb1b0 | 140 | wait(10); |
KurtDiver | 0:a096c02fb1b0 | 141 | |
KurtDiver | 0:a096c02fb1b0 | 142 | |
KurtDiver | 0:a096c02fb1b0 | 143 | } |
KurtDiver | 0:a096c02fb1b0 | 144 | } |
KurtDiver | 0:a096c02fb1b0 | 145 | void blinkRG(int blinkduration) |
KurtDiver | 0:a096c02fb1b0 | 146 | { |
KurtDiver | 0:a096c02fb1b0 | 147 | // blinkduration is measured in seconds |
KurtDiver | 0:a096c02fb1b0 | 148 | led_red=1; |
KurtDiver | 0:a096c02fb1b0 | 149 | led_green=0; |
KurtDiver | 0:a096c02fb1b0 | 150 | while (blinkduration-- >=1){ |
KurtDiver | 0:a096c02fb1b0 | 151 | led_red = led_green; |
KurtDiver | 0:a096c02fb1b0 | 152 | led_green=!led_red; |
KurtDiver | 0:a096c02fb1b0 | 153 | wait(1); |
KurtDiver | 0:a096c02fb1b0 | 154 | } |
KurtDiver | 0:a096c02fb1b0 | 155 | // leave the function with LEDs both off |
KurtDiver | 0:a096c02fb1b0 | 156 | led_red=1; |
KurtDiver | 0:a096c02fb1b0 | 157 | led_green=1; |
KurtDiver | 0:a096c02fb1b0 | 158 | |
KurtDiver | 0:a096c02fb1b0 | 159 | } |
KurtDiver | 0:a096c02fb1b0 | 160 | void check_sw3(void) |
KurtDiver | 0:a096c02fb1b0 | 161 | { |
KurtDiver | 0:a096c02fb1b0 | 162 | if (sw3 == 0) { |
KurtDiver | 0:a096c02fb1b0 | 163 | pc.printf("SW3 button pressed. \r\n"); |
KurtDiver | 0:a096c02fb1b0 | 164 | // this button press is used to pause transmissions (to save data if the device is on forever); |
KurtDiver | 0:a096c02fb1b0 | 165 | pc.printf("Transmissions are paused. \r\n"); |
KurtDiver | 0:a096c02fb1b0 | 166 | // turn on RED LED |
KurtDiver | 0:a096c02fb1b0 | 167 | led_green = 1; |
KurtDiver | 0:a096c02fb1b0 | 168 | led_red = 0; |
KurtDiver | 0:a096c02fb1b0 | 169 | // wait a few seconds for user to release the button. |
KurtDiver | 0:a096c02fb1b0 | 170 | wait(3); |
KurtDiver | 0:a096c02fb1b0 | 171 | |
KurtDiver | 0:a096c02fb1b0 | 172 | // wait until user presses the button again to unpause |
KurtDiver | 0:a096c02fb1b0 | 173 | while(sw3 ==1); |
KurtDiver | 0:a096c02fb1b0 | 174 | pc.printf("Transmissions resumed. \r\n"); |
KurtDiver | 0:a096c02fb1b0 | 175 | // turn LEDs off |
KurtDiver | 0:a096c02fb1b0 | 176 | led_green = 1; |
KurtDiver | 0:a096c02fb1b0 | 177 | led_red = 1; |
KurtDiver | 0:a096c02fb1b0 | 178 | } |
KurtDiver | 0:a096c02fb1b0 | 179 | } |
KurtDiver | 0:a096c02fb1b0 | 180 | |
KurtDiver | 0:a096c02fb1b0 | 181 | int main() { |
KurtDiver | 0:a096c02fb1b0 | 182 | |
KurtDiver | 0:a096c02fb1b0 | 183 | led_red = 1; |
KurtDiver | 0:a096c02fb1b0 | 184 | led_green = 1; |
KurtDiver | 0:a096c02fb1b0 | 185 | float axis[3]; |
KurtDiver | 0:a096c02fb1b0 | 186 | float press; |
kylerodgers | 1:e05da6207ebb | 187 | float temp; |
kylerodgers | 1:e05da6207ebb | 188 | float humi; |
kylerodgers | 1:e05da6207ebb | 189 | float dummy_temp; |
KurtDiver | 0:a096c02fb1b0 | 190 | |
KurtDiver | 0:a096c02fb1b0 | 191 | // turn on Skywire modem |
KurtDiver | 0:a096c02fb1b0 | 192 | skywire_en = 1; |
KurtDiver | 0:a096c02fb1b0 | 193 | |
KurtDiver | 0:a096c02fb1b0 | 194 | // setup skywire UART |
KurtDiver | 0:a096c02fb1b0 | 195 | skywire_rts=0; |
KurtDiver | 0:a096c02fb1b0 | 196 | skywire_dtr=0; |
KurtDiver | 0:a096c02fb1b0 | 197 | skywire.baud(115200); |
KurtDiver | 0:a096c02fb1b0 | 198 | skywire.format(8, Serial::None, 1); |
KurtDiver | 0:a096c02fb1b0 | 199 | |
KurtDiver | 0:a096c02fb1b0 | 200 | // setup Skywire UART interrupt |
KurtDiver | 0:a096c02fb1b0 | 201 | skywire.attach(&Skywire_Rx_interrupt, skywire.RxIrq); |
KurtDiver | 0:a096c02fb1b0 | 202 | |
KurtDiver | 0:a096c02fb1b0 | 203 | pc.baud(115200); |
KurtDiver | 0:a096c02fb1b0 | 204 | pc.printf("Hello World from FRDM-K64F board.\r\n"); |
KurtDiver | 0:a096c02fb1b0 | 205 | pc.printf("Starting Demo...\r\n"); |
KurtDiver | 0:a096c02fb1b0 | 206 | pc.printf("Waiting for Skywire to Boot...\r\n"); |
KurtDiver | 0:a096c02fb1b0 | 207 | |
KurtDiver | 0:a096c02fb1b0 | 208 | // wait 10 seconds for modem to boot up and connect to network |
KurtDiver | 0:a096c02fb1b0 | 209 | blinkRG(10); |
KurtDiver | 0:a096c02fb1b0 | 210 | pc.printf("Waiting complete...\r\n"); |
KurtDiver | 0:a096c02fb1b0 | 211 | |
KurtDiver | 0:a096c02fb1b0 | 212 | LM75_temp.open(); |
KurtDiver | 0:a096c02fb1b0 | 213 | |
KurtDiver | 0:a096c02fb1b0 | 214 | //Turn off echo |
KurtDiver | 0:a096c02fb1b0 | 215 | skywire.printf("ATE0\r\n"); |
KurtDiver | 0:a096c02fb1b0 | 216 | WaitForResponse("OK", 2); |
KurtDiver | 0:a096c02fb1b0 | 217 | |
KurtDiver | 0:a096c02fb1b0 | 218 | // check to see if switch 2 is pressed, if so, execute provisioning sequence |
KurtDiver | 0:a096c02fb1b0 | 219 | check_sw2(); |
KurtDiver | 0:a096c02fb1b0 | 220 | |
KurtDiver | 0:a096c02fb1b0 | 221 | |
KurtDiver | 0:a096c02fb1b0 | 222 | // read out MEID number to use as unique identifier |
KurtDiver | 0:a096c02fb1b0 | 223 | skywire.printf("AT#MEIDESN?\r\n"); |
KurtDiver | 0:a096c02fb1b0 | 224 | wait(2); |
KurtDiver | 0:a096c02fb1b0 | 225 | read_line(); |
KurtDiver | 0:a096c02fb1b0 | 226 | read_line(); |
KurtDiver | 0:a096c02fb1b0 | 227 | sscanf(rx_line, "%*s %14s,", DeviceID); |
KurtDiver | 0:a096c02fb1b0 | 228 | |
KurtDiver | 0:a096c02fb1b0 | 229 | pc.printf("Device MEID: %s \r\n", DeviceID); |
KurtDiver | 0:a096c02fb1b0 | 230 | |
KurtDiver | 0:a096c02fb1b0 | 231 | pc.printf("Connecting to Network...\r\n"); |
KurtDiver | 0:a096c02fb1b0 | 232 | // get IP address |
KurtDiver | 0:a096c02fb1b0 | 233 | skywire.printf("AT#SGACT=1,1\r\n"); |
KurtDiver | 0:a096c02fb1b0 | 234 | WaitForResponse("#SGACT", 6); |
KurtDiver | 0:a096c02fb1b0 | 235 | WaitForResponse("OK", 2); |
KurtDiver | 0:a096c02fb1b0 | 236 | // use LEDs to indicate we're connected to the newtork |
KurtDiver | 0:a096c02fb1b0 | 237 | led_red=0; |
KurtDiver | 0:a096c02fb1b0 | 238 | led_green=0; |
KurtDiver | 0:a096c02fb1b0 | 239 | |
KurtDiver | 0:a096c02fb1b0 | 240 | // connect to dweet.io |
KurtDiver | 0:a096c02fb1b0 | 241 | skywire.printf("AT#HTTPCFG=1,\"dweet.io\",80,0\r\n"); |
KurtDiver | 0:a096c02fb1b0 | 242 | WaitForResponse("OK", 2); |
KurtDiver | 0:a096c02fb1b0 | 243 | |
KurtDiver | 0:a096c02fb1b0 | 244 | //get location approximation from cell tower information |
KurtDiver | 0:a096c02fb1b0 | 245 | skywire.printf("AT#AGPSSND\r\n"); |
KurtDiver | 0:a096c02fb1b0 | 246 | WaitForResponse("#AGPSRING:", 10); |
KurtDiver | 0:a096c02fb1b0 | 247 | |
KurtDiver | 0:a096c02fb1b0 | 248 | //debug_pc.printf("Skywire says: %s\r\n", rx_line); |
KurtDiver | 0:a096c02fb1b0 | 249 | sscanf(rx_line, "%s %d,%f,%f,", str, &number, &latitude, &longitude); |
KurtDiver | 0:a096c02fb1b0 | 250 | //debug_pc.printf("Location: Latt:%f, Long:%f\r\n", latitude, longitude); |
KurtDiver | 0:a096c02fb1b0 | 251 | wait(3); |
KurtDiver | 0:a096c02fb1b0 | 252 | |
KurtDiver | 0:a096c02fb1b0 | 253 | while(1) { |
kylerodgers | 1:e05da6207ebb | 254 | temp = (float)LM75_temp; |
kylerodgers | 1:e05da6207ebb | 255 | temp = temp *9 /5 + 32; |
KurtDiver | 0:a096c02fb1b0 | 256 | pc.printf("Temp = %.3f\r\n", temp); |
kylerodgers | 1:e05da6207ebb | 257 | press=(float)pressure.value() / 4096; |
KurtDiver | 0:a096c02fb1b0 | 258 | pc.printf("Pressure = %.3f\r\n", press); |
kylerodgers | 1:e05da6207ebb | 259 | humidity.ReadTempHumi(&dummy_temp, &humi); |
kylerodgers | 1:e05da6207ebb | 260 | pc.printf("Humidity = %.3f\r\n", humi); |
KurtDiver | 0:a096c02fb1b0 | 261 | accel.read_data(axis); |
KurtDiver | 0:a096c02fb1b0 | 262 | pc.printf("Accel = %.3f, %.3f, %.3f\r\n", axis[0], axis[1], axis[2]); |
KurtDiver | 0:a096c02fb1b0 | 263 | |
KurtDiver | 0:a096c02fb1b0 | 264 | wait(0.25); |
KurtDiver | 0:a096c02fb1b0 | 265 | // turn LED Green to indicate transmission |
KurtDiver | 0:a096c02fb1b0 | 266 | led_red=1; |
KurtDiver | 0:a096c02fb1b0 | 267 | led_green = 0; |
KurtDiver | 0:a096c02fb1b0 | 268 | |
KurtDiver | 0:a096c02fb1b0 | 269 | //Report Sensor Data to dweet.io |
kylerodgers | 1:e05da6207ebb | 270 | skywire.printf("AT#HTTPQRY=1,0,\"/dweet/for/%s?temp=%.3f&press=%.3f&humi=%.3f&X=%.3f&Y=%.3f&Z=%.3f&Latitude=%f&Longitude=%f\"\r\n", DeviceID, temp, press, humi, axis[0], axis[1], axis[2], latitude, longitude); |
KurtDiver | 0:a096c02fb1b0 | 271 | WaitForResponse("#HTTPRING", 9); |
KurtDiver | 0:a096c02fb1b0 | 272 | skywire.printf("AT#HTTPRCV=1\r\n"); |
KurtDiver | 0:a096c02fb1b0 | 273 | WaitForResponse("OK", 2); |
KurtDiver | 0:a096c02fb1b0 | 274 | led_green = 1; |
KurtDiver | 0:a096c02fb1b0 | 275 | wait(2); |
KurtDiver | 0:a096c02fb1b0 | 276 | // see if user has requested to pause transmissions |
KurtDiver | 0:a096c02fb1b0 | 277 | check_sw3(); |
KurtDiver | 0:a096c02fb1b0 | 278 | } |
KurtDiver | 0:a096c02fb1b0 | 279 | |
KurtDiver | 0:a096c02fb1b0 | 280 | |
KurtDiver | 0:a096c02fb1b0 | 281 | |
KurtDiver | 0:a096c02fb1b0 | 282 | |
KurtDiver | 0:a096c02fb1b0 | 283 | } |