Mobile Life IoT project using the AT&T IoT Starter Kit Software and files for my device to monitor the status or our Airstream travel trailer RV. A full description of the project is at Hackster.IO here as part of the Realtime AT&T IoT Starter Kit Challenge: https://www.hackster.io/Anubus/mobile-life-iot-9c10be
Dependencies: FXOS8700CQ MODSERIAL mbed
main.cpp@0:bd276b1f1249, 2017-04-02 (annotated)
- Committer:
- Anubus
- Date:
- Sun Apr 02 12:28:21 2017 +0000
- Revision:
- 0:bd276b1f1249
public version commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Anubus | 0:bd276b1f1249 | 1 | /* =================================================================== |
Anubus | 0:bd276b1f1249 | 2 | Copyright © 2016, AVNET Inc. |
Anubus | 0:bd276b1f1249 | 3 | |
Anubus | 0:bd276b1f1249 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); |
Anubus | 0:bd276b1f1249 | 5 | you may not use this file except in compliance with the License. |
Anubus | 0:bd276b1f1249 | 6 | You may obtain a copy of the License at |
Anubus | 0:bd276b1f1249 | 7 | |
Anubus | 0:bd276b1f1249 | 8 | http://www.apache.org/licenses/LICENSE-2.0 |
Anubus | 0:bd276b1f1249 | 9 | |
Anubus | 0:bd276b1f1249 | 10 | Unless required by applicable law or agreed to in writing, |
Anubus | 0:bd276b1f1249 | 11 | software distributed under the License is distributed on an |
Anubus | 0:bd276b1f1249 | 12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, |
Anubus | 0:bd276b1f1249 | 13 | either express or implied. See the License for the specific |
Anubus | 0:bd276b1f1249 | 14 | language governing permissions and limitations under the License. |
Anubus | 0:bd276b1f1249 | 15 | |
Anubus | 0:bd276b1f1249 | 16 | ======================================================= |
Anubus | 0:bd276b1f1249 | 17 | Modified by Robert Bolling |
Anubus | 0:bd276b1f1249 | 18 | January 2017 |
Anubus | 0:bd276b1f1249 | 19 | for the Mobile Life IoT project |
Anubus | 0:bd276b1f1249 | 20 | - refactored to add new sensor lists from |
Anubus | 0:bd276b1f1249 | 21 | "config_me.h", and "sensors.cpp" |
Anubus | 0:bd276b1f1249 | 22 | ======================================================= |
Anubus | 0:bd276b1f1249 | 23 | |
Anubus | 0:bd276b1f1249 | 24 | ======================================================================== */ |
Anubus | 0:bd276b1f1249 | 25 | |
Anubus | 0:bd276b1f1249 | 26 | #include "mbed.h" |
Anubus | 0:bd276b1f1249 | 27 | #include <cctype> |
Anubus | 0:bd276b1f1249 | 28 | #include <string> |
Anubus | 0:bd276b1f1249 | 29 | #include "config_me.h" |
Anubus | 0:bd276b1f1249 | 30 | #include "sensors.h" |
Anubus | 0:bd276b1f1249 | 31 | #include "cell_modem.h" |
Anubus | 0:bd276b1f1249 | 32 | #include "hardware.h" |
Anubus | 0:bd276b1f1249 | 33 | |
Anubus | 0:bd276b1f1249 | 34 | I2C i2c(PTC11, PTC10); //SDA, SCL -- define the I2C pins being used - I2C1 |
Anubus | 0:bd276b1f1249 | 35 | MODSERIAL pc(USBTX, USBRX, 256, 256); // tx, rx with default tx, rx buffer sizes |
Anubus | 0:bd276b1f1249 | 36 | MODSERIAL mdm(PTD3, PTD2, 4096, 4096); |
Anubus | 0:bd276b1f1249 | 37 | DigitalOut led_green(LED_GREEN); |
Anubus | 0:bd276b1f1249 | 38 | DigitalOut led_red(LED_RED); |
Anubus | 0:bd276b1f1249 | 39 | DigitalOut led_blue(LED_BLUE); |
Anubus | 0:bd276b1f1249 | 40 | |
Anubus | 0:bd276b1f1249 | 41 | |
Anubus | 0:bd276b1f1249 | 42 | //******************************************************************************************************************************************** |
Anubus | 0:bd276b1f1249 | 43 | //* Create string with sensor readings that can be sent to flow as an HTTP get |
Anubus | 0:bd276b1f1249 | 44 | //******************************************************************************************************************************************** |
Anubus | 0:bd276b1f1249 | 45 | K64F_Sensors_t SENSOR_DATA = |
Anubus | 0:bd276b1f1249 | 46 | { |
Anubus | 0:bd276b1f1249 | 47 | .Temperature = "0", |
Anubus | 0:bd276b1f1249 | 48 | .Humidity = "0", |
Anubus | 0:bd276b1f1249 | 49 | .AccelX = "0", |
Anubus | 0:bd276b1f1249 | 50 | .AccelY = "0", |
Anubus | 0:bd276b1f1249 | 51 | .AccelZ = "0", |
Anubus | 0:bd276b1f1249 | 52 | .MagnetometerX = "0", |
Anubus | 0:bd276b1f1249 | 53 | .MagnetometerY = "0", |
Anubus | 0:bd276b1f1249 | 54 | .MagnetometerZ = "0", |
Anubus | 0:bd276b1f1249 | 55 | .Temperature_Si7020 = "0", |
Anubus | 0:bd276b1f1249 | 56 | .Humidity_Si7020 = "0", |
Anubus | 0:bd276b1f1249 | 57 | .GPS_Satellites = "0", |
Anubus | 0:bd276b1f1249 | 58 | .GPS_Latitude = "0", |
Anubus | 0:bd276b1f1249 | 59 | .GPS_Longitude = "0", |
Anubus | 0:bd276b1f1249 | 60 | .GPS_Altitude = "0", |
Anubus | 0:bd276b1f1249 | 61 | .GPS_Speed = "0", |
Anubus | 0:bd276b1f1249 | 62 | .GPS_Course = "0", |
Anubus | 0:bd276b1f1249 | 63 | .Battery_Voltage = "0", |
Anubus | 0:bd276b1f1249 | 64 | .Intrusion_Detected = "0" |
Anubus | 0:bd276b1f1249 | 65 | }; |
Anubus | 0:bd276b1f1249 | 66 | |
Anubus | 0:bd276b1f1249 | 67 | void display_app_firmware_version(void) |
Anubus | 0:bd276b1f1249 | 68 | { |
Anubus | 0:bd276b1f1249 | 69 | PUTS("\r\n\r\nApp Firmware: Release 1.0 - built: "__DATE__" "__TIME__"\r\n\r\n"); |
Anubus | 0:bd276b1f1249 | 70 | } |
Anubus | 0:bd276b1f1249 | 71 | |
Anubus | 0:bd276b1f1249 | 72 | void GenerateModemString(char * modem_string) |
Anubus | 0:bd276b1f1249 | 73 | { |
Anubus | 0:bd276b1f1249 | 74 | switch(iSensorsToReport) |
Anubus | 0:bd276b1f1249 | 75 | { |
Anubus | 0:bd276b1f1249 | 76 | case SHIELDTEMP_ACCELEROMETER_BATTERY: |
Anubus | 0:bd276b1f1249 | 77 | { |
Anubus | 0:bd276b1f1249 | 78 | sprintf(modem_string, "GET %s%s?serial=%s&temp=%s&humidity=%s&accelX=%s&accelY=%s&accelZ=%s&batt_volt=%s %s%s\r\n\r\n", FLOW_BASE_URL, FLOW_INPUT_NAME, FLOW_DEVICE_NAME, SENSOR_DATA.Temperature, SENSOR_DATA.Humidity, SENSOR_DATA.AccelX,SENSOR_DATA.AccelY, SENSOR_DATA.AccelZ, SENSOR_DATA.Battery_Voltage, FLOW_URL_TYPE, MY_SERVER_URL); |
Anubus | 0:bd276b1f1249 | 79 | break; |
Anubus | 0:bd276b1f1249 | 80 | } |
Anubus | 0:bd276b1f1249 | 81 | case SHIELDTEMP_ACCELEROMETER_BATTERY_INTRUSION: |
Anubus | 0:bd276b1f1249 | 82 | { |
Anubus | 0:bd276b1f1249 | 83 | sprintf(modem_string, "GET %s%s?serial=%s&temp=%s&humidity=%s&accelX=%s&accelY=%s&accelZ=%s&batt_volt=%s&intrusion=%s %s%s\r\n\r\n", FLOW_BASE_URL, FLOW_INPUT_NAME, FLOW_DEVICE_NAME, SENSOR_DATA.Temperature, SENSOR_DATA.Humidity, SENSOR_DATA.AccelX,SENSOR_DATA.AccelY, SENSOR_DATA.AccelZ, SENSOR_DATA.Battery_Voltage, SENSOR_DATA.Intrusion_Detected, FLOW_URL_TYPE, MY_SERVER_URL); |
Anubus | 0:bd276b1f1249 | 84 | break; |
Anubus | 0:bd276b1f1249 | 85 | } |
Anubus | 0:bd276b1f1249 | 86 | case SHIELDTEMP_ACCELEROMETER_BATTERY_GPS: |
Anubus | 0:bd276b1f1249 | 87 | { |
Anubus | 0:bd276b1f1249 | 88 | sprintf(modem_string, "GET %s%s?serial=%s&temp=%s&humidity=%s&accelX=%s&accelY=%s&accelZ=%s&batt_volt=%s&gps_satellites=%s&latitude=%s&longitude=%s&altitude=%s&speed=%s&course=%s %s%s\r\n\r\n", FLOW_BASE_URL, FLOW_INPUT_NAME, FLOW_DEVICE_NAME, SENSOR_DATA.Temperature, SENSOR_DATA.Humidity, SENSOR_DATA.AccelX,SENSOR_DATA.AccelY, SENSOR_DATA.AccelZ, SENSOR_DATA.Battery_Voltage, SENSOR_DATA.GPS_Satellites,SENSOR_DATA.GPS_Latitude,SENSOR_DATA.GPS_Longitude,SENSOR_DATA.GPS_Altitude,SENSOR_DATA.GPS_Speed,SENSOR_DATA.GPS_Course, FLOW_URL_TYPE, MY_SERVER_URL); |
Anubus | 0:bd276b1f1249 | 89 | break; |
Anubus | 0:bd276b1f1249 | 90 | } |
Anubus | 0:bd276b1f1249 | 91 | case SHIELDTEMP_ACCELEROMETER_BATTERY_EXTERNALTEMP: |
Anubus | 0:bd276b1f1249 | 92 | { |
Anubus | 0:bd276b1f1249 | 93 | sprintf(modem_string, "GET %s%s?serial=%s&temp=%s&humidity=%s&accelX=%s&accelY=%s&accelZ=%s&batt_volt=%s&temp2=%s&humidity2=%s %s%s\r\n\r\n", FLOW_BASE_URL, FLOW_INPUT_NAME, FLOW_DEVICE_NAME, SENSOR_DATA.Temperature, SENSOR_DATA.Humidity, SENSOR_DATA.AccelX,SENSOR_DATA.AccelY, SENSOR_DATA.AccelZ, SENSOR_DATA.Battery_Voltage, SENSOR_DATA.Temperature_Si7020, SENSOR_DATA.Humidity_Si7020, FLOW_URL_TYPE, MY_SERVER_URL); |
Anubus | 0:bd276b1f1249 | 94 | break; |
Anubus | 0:bd276b1f1249 | 95 | } |
Anubus | 0:bd276b1f1249 | 96 | case SHIELDTEMP_ACCELEROMETER_BATTERY_EXTERNALTEMP_GPS: |
Anubus | 0:bd276b1f1249 | 97 | { |
Anubus | 0:bd276b1f1249 | 98 | sprintf(modem_string, "GET %s%s?serial=%s&temp=%s&humidity=%s&accelX=%s&accelY=%s&accelZ=%s&batt_volt=%s&temp2=%s&humidity2=%s&gps_satellites=%s&latitude=%s&longitude=%s&altitude=%s&speed=%s&course=%s %s%s\r\n\r\n", FLOW_BASE_URL, FLOW_INPUT_NAME, FLOW_DEVICE_NAME, SENSOR_DATA.Temperature, SENSOR_DATA.Humidity, SENSOR_DATA.AccelX,SENSOR_DATA.AccelY, SENSOR_DATA.AccelZ, SENSOR_DATA.Battery_Voltage, SENSOR_DATA.Temperature_Si7020, SENSOR_DATA.Humidity_Si7020, SENSOR_DATA.GPS_Satellites,SENSOR_DATA.GPS_Latitude,SENSOR_DATA.GPS_Longitude,SENSOR_DATA.GPS_Altitude,SENSOR_DATA.GPS_Speed,SENSOR_DATA.GPS_Course, FLOW_URL_TYPE, MY_SERVER_URL); |
Anubus | 0:bd276b1f1249 | 99 | break; |
Anubus | 0:bd276b1f1249 | 100 | } |
Anubus | 0:bd276b1f1249 | 101 | case SHIELDTEMP_ACCELEROMETER_BATTERY_EXTERNALTEMP_GPS_INTRUSION: |
Anubus | 0:bd276b1f1249 | 102 | { |
Anubus | 0:bd276b1f1249 | 103 | sprintf(modem_string, "GET %s%s?serial=%s&temp=%s&humidity=%s&accelX=%s&accelY=%s&accelZ=%s&batt_volt=%s&temp2=%s&humidity2=%s&gps_satellites=%s&latitude=%s&longitude=%s&altitude=%s&speed=%s&course=%s&intrusion=%s %s%s\r\n\r\n", FLOW_BASE_URL, FLOW_INPUT_NAME, FLOW_DEVICE_NAME, SENSOR_DATA.Temperature, SENSOR_DATA.Humidity, SENSOR_DATA.AccelX,SENSOR_DATA.AccelY, SENSOR_DATA.AccelZ, SENSOR_DATA.Battery_Voltage, SENSOR_DATA.Temperature_Si7020, SENSOR_DATA.Humidity_Si7020, SENSOR_DATA.GPS_Satellites,SENSOR_DATA.GPS_Latitude,SENSOR_DATA.GPS_Longitude,SENSOR_DATA.GPS_Altitude,SENSOR_DATA.GPS_Speed,SENSOR_DATA.GPS_Course, SENSOR_DATA.Intrusion_Detected, FLOW_URL_TYPE, MY_SERVER_URL); |
Anubus | 0:bd276b1f1249 | 104 | break; |
Anubus | 0:bd276b1f1249 | 105 | } |
Anubus | 0:bd276b1f1249 | 106 | default: |
Anubus | 0:bd276b1f1249 | 107 | { |
Anubus | 0:bd276b1f1249 | 108 | sprintf(modem_string, "Invalid sensor selected\r\n\r\n"); |
Anubus | 0:bd276b1f1249 | 109 | break; |
Anubus | 0:bd276b1f1249 | 110 | } |
Anubus | 0:bd276b1f1249 | 111 | } //switch(iSensorsToReport) |
Anubus | 0:bd276b1f1249 | 112 | } //GenerateModemString |
Anubus | 0:bd276b1f1249 | 113 | |
Anubus | 0:bd276b1f1249 | 114 | |
Anubus | 0:bd276b1f1249 | 115 | //Periodic timer |
Anubus | 0:bd276b1f1249 | 116 | Ticker OneMsTicker; |
Anubus | 0:bd276b1f1249 | 117 | volatile bool bTimerExpiredFlag = false; |
Anubus | 0:bd276b1f1249 | 118 | int OneMsTicks = 0; |
Anubus | 0:bd276b1f1249 | 119 | int iTimer1Interval_ms = 1000; |
Anubus | 0:bd276b1f1249 | 120 | //******************************************************************************************************************************************** |
Anubus | 0:bd276b1f1249 | 121 | //* Periodic 1ms timer tick |
Anubus | 0:bd276b1f1249 | 122 | //******************************************************************************************************************************************** |
Anubus | 0:bd276b1f1249 | 123 | void OneMsFunction() |
Anubus | 0:bd276b1f1249 | 124 | { |
Anubus | 0:bd276b1f1249 | 125 | OneMsTicks++; |
Anubus | 0:bd276b1f1249 | 126 | if ((OneMsTicks % iTimer1Interval_ms) == 0) |
Anubus | 0:bd276b1f1249 | 127 | { |
Anubus | 0:bd276b1f1249 | 128 | bTimerExpiredFlag = true; |
Anubus | 0:bd276b1f1249 | 129 | } |
Anubus | 0:bd276b1f1249 | 130 | } //OneMsFunction() |
Anubus | 0:bd276b1f1249 | 131 | |
Anubus | 0:bd276b1f1249 | 132 | //******************************************************************************************************************************************** |
Anubus | 0:bd276b1f1249 | 133 | //* Set the RGB LED's Color |
Anubus | 0:bd276b1f1249 | 134 | //* LED Color 0=Off to 7=White. 3 bits represent BGR (bit0=Red, bit1=Green, bit2=Blue) |
Anubus | 0:bd276b1f1249 | 135 | //******************************************************************************************************************************************** |
Anubus | 0:bd276b1f1249 | 136 | void SetLedColor(unsigned char ucColor) |
Anubus | 0:bd276b1f1249 | 137 | { |
Anubus | 0:bd276b1f1249 | 138 | //Note that when an LED is on, you write a 0 to it: |
Anubus | 0:bd276b1f1249 | 139 | led_red = !(ucColor & 0x1); //bit 0 |
Anubus | 0:bd276b1f1249 | 140 | led_green = !(ucColor & 0x2); //bit 1 |
Anubus | 0:bd276b1f1249 | 141 | led_blue = !(ucColor & 0x4); //bit 2 |
Anubus | 0:bd276b1f1249 | 142 | } //SetLedColor() |
Anubus | 0:bd276b1f1249 | 143 | |
Anubus | 0:bd276b1f1249 | 144 | //******************************************************************************************************************************************** |
Anubus | 0:bd276b1f1249 | 145 | //* Process the JSON response. In this example we are only extracting a LED color. |
Anubus | 0:bd276b1f1249 | 146 | //******************************************************************************************************************************************** |
Anubus | 0:bd276b1f1249 | 147 | bool parse_JSON(char* json_string) |
Anubus | 0:bd276b1f1249 | 148 | { |
Anubus | 0:bd276b1f1249 | 149 | char* beginquote; |
Anubus | 0:bd276b1f1249 | 150 | char token[] = "\"LED\":\""; |
Anubus | 0:bd276b1f1249 | 151 | beginquote = strstr(json_string, token ); |
Anubus | 0:bd276b1f1249 | 152 | if ((beginquote != 0)) |
Anubus | 0:bd276b1f1249 | 153 | { |
Anubus | 0:bd276b1f1249 | 154 | char cLedColor = beginquote[strlen(token)]; |
Anubus | 0:bd276b1f1249 | 155 | PRINTF(GRN "LED Found : %c" DEF "\r\n", cLedColor); |
Anubus | 0:bd276b1f1249 | 156 | switch(cLedColor) |
Anubus | 0:bd276b1f1249 | 157 | { |
Anubus | 0:bd276b1f1249 | 158 | case 'O': |
Anubus | 0:bd276b1f1249 | 159 | { //Off |
Anubus | 0:bd276b1f1249 | 160 | SetLedColor(0); |
Anubus | 0:bd276b1f1249 | 161 | break; |
Anubus | 0:bd276b1f1249 | 162 | } |
Anubus | 0:bd276b1f1249 | 163 | case 'R': |
Anubus | 0:bd276b1f1249 | 164 | { //Red |
Anubus | 0:bd276b1f1249 | 165 | SetLedColor(1); |
Anubus | 0:bd276b1f1249 | 166 | break; |
Anubus | 0:bd276b1f1249 | 167 | } |
Anubus | 0:bd276b1f1249 | 168 | case 'G': |
Anubus | 0:bd276b1f1249 | 169 | { //Green |
Anubus | 0:bd276b1f1249 | 170 | SetLedColor(2); |
Anubus | 0:bd276b1f1249 | 171 | break; |
Anubus | 0:bd276b1f1249 | 172 | } |
Anubus | 0:bd276b1f1249 | 173 | case 'Y': |
Anubus | 0:bd276b1f1249 | 174 | { //Yellow |
Anubus | 0:bd276b1f1249 | 175 | SetLedColor(3); |
Anubus | 0:bd276b1f1249 | 176 | break; |
Anubus | 0:bd276b1f1249 | 177 | } |
Anubus | 0:bd276b1f1249 | 178 | case 'B': |
Anubus | 0:bd276b1f1249 | 179 | { //Blue |
Anubus | 0:bd276b1f1249 | 180 | SetLedColor(4); |
Anubus | 0:bd276b1f1249 | 181 | break; |
Anubus | 0:bd276b1f1249 | 182 | } |
Anubus | 0:bd276b1f1249 | 183 | case 'M': |
Anubus | 0:bd276b1f1249 | 184 | { //Magenta |
Anubus | 0:bd276b1f1249 | 185 | SetLedColor(5); |
Anubus | 0:bd276b1f1249 | 186 | break; |
Anubus | 0:bd276b1f1249 | 187 | } |
Anubus | 0:bd276b1f1249 | 188 | case 'T': |
Anubus | 0:bd276b1f1249 | 189 | { //Turquoise |
Anubus | 0:bd276b1f1249 | 190 | SetLedColor(6); |
Anubus | 0:bd276b1f1249 | 191 | break; |
Anubus | 0:bd276b1f1249 | 192 | } |
Anubus | 0:bd276b1f1249 | 193 | case 'W': |
Anubus | 0:bd276b1f1249 | 194 | { //White |
Anubus | 0:bd276b1f1249 | 195 | SetLedColor(7); |
Anubus | 0:bd276b1f1249 | 196 | break; |
Anubus | 0:bd276b1f1249 | 197 | } |
Anubus | 0:bd276b1f1249 | 198 | default: |
Anubus | 0:bd276b1f1249 | 199 | { |
Anubus | 0:bd276b1f1249 | 200 | break; |
Anubus | 0:bd276b1f1249 | 201 | } |
Anubus | 0:bd276b1f1249 | 202 | } //switch(cLedColor) |
Anubus | 0:bd276b1f1249 | 203 | return true; |
Anubus | 0:bd276b1f1249 | 204 | } |
Anubus | 0:bd276b1f1249 | 205 | else |
Anubus | 0:bd276b1f1249 | 206 | { |
Anubus | 0:bd276b1f1249 | 207 | return false; |
Anubus | 0:bd276b1f1249 | 208 | } |
Anubus | 0:bd276b1f1249 | 209 | } //parse_JSON |
Anubus | 0:bd276b1f1249 | 210 | |
Anubus | 0:bd276b1f1249 | 211 | int main() { |
Anubus | 0:bd276b1f1249 | 212 | static unsigned ledOnce = 0; |
Anubus | 0:bd276b1f1249 | 213 | //delay so that the debug terminal can open after power-on reset: |
Anubus | 0:bd276b1f1249 | 214 | wait (5.0); |
Anubus | 0:bd276b1f1249 | 215 | pc.baud(115200); |
Anubus | 0:bd276b1f1249 | 216 | |
Anubus | 0:bd276b1f1249 | 217 | display_app_firmware_version(); |
Anubus | 0:bd276b1f1249 | 218 | |
Anubus | 0:bd276b1f1249 | 219 | PRINTF(GRN "Hello World from the Cellular IoT Kit!\r\n\r\n"); |
Anubus | 0:bd276b1f1249 | 220 | |
Anubus | 0:bd276b1f1249 | 221 | //Initialize the I2C sensors that are present |
Anubus | 0:bd276b1f1249 | 222 | sensors_init(); |
Anubus | 0:bd276b1f1249 | 223 | read_sensors(); |
Anubus | 0:bd276b1f1249 | 224 | |
Anubus | 0:bd276b1f1249 | 225 | // Set LED to RED until init finishes |
Anubus | 0:bd276b1f1249 | 226 | SetLedColor(0x1); //Red |
Anubus | 0:bd276b1f1249 | 227 | // Initialize the modem |
Anubus | 0:bd276b1f1249 | 228 | PRINTF("\r\n"); |
Anubus | 0:bd276b1f1249 | 229 | |
Anubus | 0:bd276b1f1249 | 230 | //TODO: comment out these next two lines for local testing (no modem send) to keep from initializing the modem |
Anubus | 0:bd276b1f1249 | 231 | cell_modem_init(); |
Anubus | 0:bd276b1f1249 | 232 | display_wnc_firmware_rev(); |
Anubus | 0:bd276b1f1249 | 233 | |
Anubus | 0:bd276b1f1249 | 234 | // Set LED BLUE for partial init |
Anubus | 0:bd276b1f1249 | 235 | SetLedColor(0x4); //Blue |
Anubus | 0:bd276b1f1249 | 236 | |
Anubus | 0:bd276b1f1249 | 237 | //Create a 1ms timer tick function: |
Anubus | 0:bd276b1f1249 | 238 | iTimer1Interval_ms = SENSOR_UPDATE_INTERVAL_MS; |
Anubus | 0:bd276b1f1249 | 239 | OneMsTicker.attach(OneMsFunction, 0.001f) ; |
Anubus | 0:bd276b1f1249 | 240 | |
Anubus | 0:bd276b1f1249 | 241 | // Send and receive data perpetually |
Anubus | 0:bd276b1f1249 | 242 | while(1) { |
Anubus | 0:bd276b1f1249 | 243 | if (bTimerExpiredFlag) |
Anubus | 0:bd276b1f1249 | 244 | { |
Anubus | 0:bd276b1f1249 | 245 | bTimerExpiredFlag = false; |
Anubus | 0:bd276b1f1249 | 246 | PRINTF("Sensor readings... \n\r"); |
Anubus | 0:bd276b1f1249 | 247 | read_sensors(); //read available external sensors from external and on-board temp and motion sensors |
Anubus | 0:bd276b1f1249 | 248 | PRINTF("...end sensor readings \n\r\n\r"); |
Anubus | 0:bd276b1f1249 | 249 | |
Anubus | 0:bd276b1f1249 | 250 | |
Anubus | 0:bd276b1f1249 | 251 | |
Anubus | 0:bd276b1f1249 | 252 | char modem_string[512]; |
Anubus | 0:bd276b1f1249 | 253 | GenerateModemString(&modem_string[0]); |
Anubus | 0:bd276b1f1249 | 254 | PRINTF(modem_string); //TODO: check what is being sent |
Anubus | 0:bd276b1f1249 | 255 | // TODO: comment out to the next "TODO" for local testing to keep from sendng to modem |
Anubus | 0:bd276b1f1249 | 256 | char myJsonResponse[512]; |
Anubus | 0:bd276b1f1249 | 257 | if (cell_modem_Sendreceive(&modem_string[0], &myJsonResponse[0])) |
Anubus | 0:bd276b1f1249 | 258 | { |
Anubus | 0:bd276b1f1249 | 259 | if (!ledOnce) |
Anubus | 0:bd276b1f1249 | 260 | { |
Anubus | 0:bd276b1f1249 | 261 | ledOnce = 1; |
Anubus | 0:bd276b1f1249 | 262 | SetLedColor(0x2); //Green |
Anubus | 0:bd276b1f1249 | 263 | } |
Anubus | 0:bd276b1f1249 | 264 | parse_JSON(&myJsonResponse[0]); |
Anubus | 0:bd276b1f1249 | 265 | } |
Anubus | 0:bd276b1f1249 | 266 | // TODO: end testing comment out section |
Anubus | 0:bd276b1f1249 | 267 | |
Anubus | 0:bd276b1f1249 | 268 | |
Anubus | 0:bd276b1f1249 | 269 | } //bTimerExpiredFlag |
Anubus | 0:bd276b1f1249 | 270 | } //forever loop |
Anubus | 0:bd276b1f1249 | 271 | } |