Demo using a Nimbelink Skywire cellular modem paired with ST Nucleo. This demo reads several sensors and reports them to a Freeboard dashboard using dweet.io from Buglabs
Dependencies: LIS3DH LM75B LPS331 hts221 mbed
Fork of Skywire_Demo by
Getting Started Guide
- Set the JP5 jumper to E5V on the Nucleo
- Place the Skywire Shield onto the Nucleo as pictured
- Place the Skywire modem onto the Shield as picture and attach the antenna U.FL coax cable as pictured
- Plug the 12V wall supply into the Skywire Shield
- Go to https://freeboard.io/ and create a user account
- Once you are logged into your Freeboard account, go to https://freeboard.io/board/PJI272 and clone the dashboard by clicking the CLONE link in the lower right corner
- Old Revision of dashboard is 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 a unique string, we recommended using the MEID or IMEI on the Skywire Modem, but it could be anything you want.
- Next, Import the Skywire_Demo program into the online compiler
- Open main.cpp. Starting at Line 58, there is a list of Skywire Modems. Uncomment the Skywire Modem that you are using. Make sure only one Skywire Modem is uncommented:
main.cpp
/* * DEFINE THE SKYWIRE MODEM * Uncomment only the modem that you are using. * Make sure only one modem is uncommented! */ //#define NL_SW_1xRTT_V // Verizon 2G Modem - CE910-DUAL //#define NL_SW_1xRTT_S // Sprint 2G Modem - CE910-DUAL //#define NL_SW_1xRTT_A // Aeris 2G Modem - CE910-DUAL //#define NL_SW_GPRS // AT&T/T-Mobile 2G Modem //#define NL_SW_EVDO_V // Verizon 3G Modem //#define NL_SW_EVDO_A // Aeris 3G Modem //#define NL_SW_HSPAP // AT&T/T-Mobile 3G Modem //#define NL_SW_HSPAPG // AT&T/T-Mobile 3G Modem w/ GPS //#define NL_SW_HSPAPE // GSM 3G Modem, EU //#define NL_SW_LTE_TSVG // Verizon 4G LTE Modem //#define NL_SW_LTE_TNAG // AT&T/T-Mobile 4G LTE Modem //#define NL_SW_LTE_TEUG // GSM 4G LTE Modem, EU //#define NL_SW_LTE_GELS3 // VZW LTE Cat 1 Modem
- Next, to Line 73 in main.cpp, and change the DeviceID to the THING NAME you entered into your Freeboard:
main.cpp
/* --CHANGE THIS FOR YOUR SETUP" -- */ #define DeviceID "DweetIODeviceName" //Freeboard DweetIO unique ID
- If applicable, go to Line 77 in main.cpp and change the APN to your specific APN:
main.cpp
/* --CHANGE THIS FOR YORU SETUP (IF APPLICABLE)-- */ #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 std::string APN = "yourAPNhere"; #endif
- Compile and upload to the Nucleo, cycle power to the shield and the sensor data should start to upload to your new Freeboard.
main.cpp@3:4b2176f6474c, 2015-01-12 (annotated)
- Committer:
- kholland
- Date:
- Mon Jan 12 23:27:12 2015 +0000
- Revision:
- 3:4b2176f6474c
- Parent:
- 2:b57e24a42b6f
- Child:
- 4:e7a79d3542e1
Code to wait for correct response from skywire
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kholland | 0:3095958bc639 | 1 | |
kholland | 0:3095958bc639 | 2 | |
kholland | 0:3095958bc639 | 3 | #include "mbed.h" |
kholland | 0:3095958bc639 | 4 | #include "LPS331.h" |
kholland | 0:3095958bc639 | 5 | #include "LIS3DH.h" |
kholland | 0:3095958bc639 | 6 | #include "LM75B.h" |
kholland | 0:3095958bc639 | 7 | |
kholland | 0:3095958bc639 | 8 | /* --CHANGE THIS FOR YOUR SETUP" -- */ |
kholland | 0:3095958bc639 | 9 | #define DeviceID "mbedskywire" //Freeboard DweetIO unique ID |
kholland | 0:3095958bc639 | 10 | |
kholland | 0:3095958bc639 | 11 | DigitalOut myled(LED1); |
kholland | 0:3095958bc639 | 12 | DigitalOut skywire_en(PA_6); |
kholland | 0:3095958bc639 | 13 | DigitalOut skywire_rts(PA_7); |
kholland | 0:3095958bc639 | 14 | |
kholland | 0:3095958bc639 | 15 | Serial skywire(PA_9,PA_10); |
kholland | 0:3095958bc639 | 16 | Serial debug_pc(USBTX, USBRX); |
kholland | 0:3095958bc639 | 17 | |
kholland | 0:3095958bc639 | 18 | I2C i2c(PB_9,PB_8); |
kholland | 0:3095958bc639 | 19 | char msg[3]; |
kholland | 0:3095958bc639 | 20 | |
kholland | 0:3095958bc639 | 21 | LPS331 pressure(i2c); |
kholland | 0:3095958bc639 | 22 | LM75B LM75_temp(PB_9,PB_8); |
kholland | 0:3095958bc639 | 23 | LIS3DH accel(i2c, LIS3DH_V_CHIP_ADDR, LIS3DH_DR_NR_LP_100HZ, LIS3DH_FS_2G); |
kholland | 0:3095958bc639 | 24 | |
kholland | 0:3095958bc639 | 25 | |
kholland | 3:4b2176f6474c | 26 | char str[255]; |
kholland | 3:4b2176f6474c | 27 | |
kholland | 0:3095958bc639 | 28 | float latitude; |
kholland | 0:3095958bc639 | 29 | float longitude; |
kholland | 0:3095958bc639 | 30 | int number; |
kholland | 0:3095958bc639 | 31 | |
kholland | 3:4b2176f6474c | 32 | volatile int rx_in=0; |
kholland | 3:4b2176f6474c | 33 | volatile int rx_out=0; |
kholland | 3:4b2176f6474c | 34 | const int buffer_size = 255; |
kholland | 3:4b2176f6474c | 35 | char rx_buffer[buffer_size+1]; |
kholland | 3:4b2176f6474c | 36 | |
kholland | 3:4b2176f6474c | 37 | char rx_line[buffer_size]; |
kholland | 3:4b2176f6474c | 38 | |
kholland | 3:4b2176f6474c | 39 | void Skywire_Rx_interrupt() { |
kholland | 3:4b2176f6474c | 40 | // Loop just in case more than one character is in UART's receive FIFO buffer |
kholland | 3:4b2176f6474c | 41 | // Stop if buffer full |
kholland | 3:4b2176f6474c | 42 | while ((skywire.readable()) && (((rx_in + 1) % buffer_size) != rx_out)) { |
kholland | 3:4b2176f6474c | 43 | rx_buffer[rx_in] = skywire.getc(); |
kholland | 3:4b2176f6474c | 44 | rx_in = (rx_in + 1) % buffer_size; |
kholland | 3:4b2176f6474c | 45 | } |
kholland | 3:4b2176f6474c | 46 | return; |
kholland | 3:4b2176f6474c | 47 | } |
kholland | 3:4b2176f6474c | 48 | |
kholland | 3:4b2176f6474c | 49 | void read_line() { |
kholland | 3:4b2176f6474c | 50 | int i; |
kholland | 3:4b2176f6474c | 51 | i = 0; |
kholland | 3:4b2176f6474c | 52 | // Start Critical Section - don't interrupt while changing global buffer variables |
kholland | 3:4b2176f6474c | 53 | __disable_irq(); |
kholland | 3:4b2176f6474c | 54 | // Loop reading rx buffer characters until end of line character |
kholland | 3:4b2176f6474c | 55 | while ((i==0) || (rx_line[i-1] != '\n')) { |
kholland | 3:4b2176f6474c | 56 | // Wait if buffer empty |
kholland | 3:4b2176f6474c | 57 | if (rx_in == rx_out) { |
kholland | 3:4b2176f6474c | 58 | // End Critical Section - need to allow rx interrupt to get new characters for buffer |
kholland | 3:4b2176f6474c | 59 | __enable_irq(); |
kholland | 3:4b2176f6474c | 60 | while (rx_in == rx_out) { |
kholland | 3:4b2176f6474c | 61 | } |
kholland | 3:4b2176f6474c | 62 | // Start Critical Section - don't interrupt while changing global buffer variables |
kholland | 3:4b2176f6474c | 63 | __disable_irq(); |
kholland | 3:4b2176f6474c | 64 | } |
kholland | 3:4b2176f6474c | 65 | rx_line[i] = rx_buffer[rx_out]; |
kholland | 3:4b2176f6474c | 66 | i++; |
kholland | 3:4b2176f6474c | 67 | rx_out = (rx_out + 1) % buffer_size; |
kholland | 3:4b2176f6474c | 68 | } |
kholland | 3:4b2176f6474c | 69 | // End Critical Section |
kholland | 3:4b2176f6474c | 70 | __enable_irq(); |
kholland | 3:4b2176f6474c | 71 | rx_line[i-1] = 0; |
kholland | 3:4b2176f6474c | 72 | return; |
kholland | 3:4b2176f6474c | 73 | } |
kholland | 3:4b2176f6474c | 74 | int WaitForResponse(char* response, int num) { |
kholland | 3:4b2176f6474c | 75 | do { |
kholland | 3:4b2176f6474c | 76 | read_line(); |
kholland | 3:4b2176f6474c | 77 | debug_pc.printf("Waiting for: %s, Recieved: %s\r\n", response, rx_line); |
kholland | 3:4b2176f6474c | 78 | } while (strncmp(rx_line, response, num)); |
kholland | 3:4b2176f6474c | 79 | return 0; |
kholland | 3:4b2176f6474c | 80 | } |
kholland | 0:3095958bc639 | 81 | int main() |
kholland | 0:3095958bc639 | 82 | { |
kholland | 0:3095958bc639 | 83 | float axis[3]; |
kholland | 0:3095958bc639 | 84 | float press; |
kholland | 0:3095958bc639 | 85 | float temp; |
kholland | 0:3095958bc639 | 86 | |
kholland | 3:4b2176f6474c | 87 | |
kholland | 0:3095958bc639 | 88 | debug_pc.baud(115200); |
kholland | 0:3095958bc639 | 89 | skywire.baud(115200); |
kholland | 3:4b2176f6474c | 90 | skywire.attach(&Skywire_Rx_interrupt, Serial::RxIrq); |
kholland | 0:3095958bc639 | 91 | skywire_rts=0; |
kholland | 0:3095958bc639 | 92 | myled=0; |
kholland | 3:4b2176f6474c | 93 | debug_pc.printf("Starting Demo...\r\n"); |
kholland | 3:4b2176f6474c | 94 | debug_pc.printf("Waiting for Skywire to Boot...\r\n"); |
kholland | 0:3095958bc639 | 95 | //Enable Skywire |
kholland | 0:3095958bc639 | 96 | skywire_en=0; |
kholland | 0:3095958bc639 | 97 | wait(2); |
kholland | 0:3095958bc639 | 98 | skywire_en=1; |
kholland | 0:3095958bc639 | 99 | wait(2); |
kholland | 0:3095958bc639 | 100 | skywire_en=0; |
kholland | 3:4b2176f6474c | 101 | |
kholland | 3:4b2176f6474c | 102 | myled=1; |
kholland | 0:3095958bc639 | 103 | wait(5); |
kholland | 3:4b2176f6474c | 104 | |
kholland | 3:4b2176f6474c | 105 | LM75_temp.open(); |
kholland | 0:3095958bc639 | 106 | |
kholland | 3:4b2176f6474c | 107 | //Turn off echo |
kholland | 3:4b2176f6474c | 108 | skywire.printf("ATE0\r\n"); |
kholland | 3:4b2176f6474c | 109 | WaitForResponse("OK", 2); |
kholland | 3:4b2176f6474c | 110 | |
kholland | 3:4b2176f6474c | 111 | debug_pc.printf("Connecting to Network...\r\n"); |
kholland | 0:3095958bc639 | 112 | // get IP address |
kholland | 3:4b2176f6474c | 113 | skywire.printf("AT#SGACT=1,1\r\n"); |
kholland | 3:4b2176f6474c | 114 | WaitForResponse("#SGACT", 6); |
kholland | 3:4b2176f6474c | 115 | WaitForResponse("OK", 2); |
kholland | 0:3095958bc639 | 116 | |
kholland | 0:3095958bc639 | 117 | // connect to dweet.io |
kholland | 3:4b2176f6474c | 118 | skywire.printf("AT#HTTPCFG=1,\"dweet.io\",80,0\r\n"); |
kholland | 3:4b2176f6474c | 119 | WaitForResponse("OK", 2); |
kholland | 0:3095958bc639 | 120 | |
kholland | 0:3095958bc639 | 121 | //get location approximation from cell tower information |
kholland | 0:3095958bc639 | 122 | skywire.printf("AT#AGPSSND\r\n"); |
kholland | 3:4b2176f6474c | 123 | WaitForResponse("#AGPSRING:", 10); |
kholland | 3:4b2176f6474c | 124 | |
kholland | 3:4b2176f6474c | 125 | //debug_pc.printf("Skywire says: %s\r\n", rx_line); |
kholland | 3:4b2176f6474c | 126 | sscanf(rx_line, "%s %d,%f,%f,", str, &number, &latitude, &longitude); |
kholland | 3:4b2176f6474c | 127 | debug_pc.printf("Location: Latt:%f, Long:%f\r\n", latitude, longitude); |
kholland | 3:4b2176f6474c | 128 | wait(3); |
kholland | 3:4b2176f6474c | 129 | |
kholland | 0:3095958bc639 | 130 | while(1) { |
kholland | 0:3095958bc639 | 131 | temp = (float)LM75_temp; |
kholland | 3:4b2176f6474c | 132 | debug_pc.printf("Temp = %.3f\r\n", temp); |
kholland | 0:3095958bc639 | 133 | press=(float)pressure.value() / 4096; |
kholland | 3:4b2176f6474c | 134 | debug_pc.printf("Pressure = %.3f\r\n", press); |
kholland | 0:3095958bc639 | 135 | accel.read_data(axis); |
kholland | 3:4b2176f6474c | 136 | debug_pc.printf("Accel = %.3f, %.3f, %.3f\r\n", axis[0], axis[1], axis[2]); |
kholland | 3:4b2176f6474c | 137 | // wait(10); |
kholland | 3:4b2176f6474c | 138 | |
kholland | 0:3095958bc639 | 139 | //Report Sensor Data to dweet.io |
kholland | 0:3095958bc639 | 140 | skywire.printf("AT#HTTPQRY=1,0,\"/dweet/for/%s?temperature=%.3f&pressure=%.3f&X=%.3f&Y=%.3f&Z=%.3f&Latitude=%f&Longitude=%f\"\r\n", DeviceID, temp, press, axis[0], axis[1], axis[2], latitude, longitude); |
kholland | 3:4b2176f6474c | 141 | WaitForResponse("#HTTPRING", 9); |
kholland | 0:3095958bc639 | 142 | skywire.printf("AT#HTTPRCV=1\r\n"); |
kholland | 3:4b2176f6474c | 143 | WaitForResponse("OK", 2); |
kholland | 0:3095958bc639 | 144 | wait(5); |
kholland | 3:4b2176f6474c | 145 | } |
kholland | 0:3095958bc639 | 146 | |
kholland | 0:3095958bc639 | 147 | } |