This program connects to a few sensors via I2C and sends the data collected to a WNC Cellular Module which is located on an Avnet WNC-Shield card.

Dependencies:   FXOS8700CQ MODSERIAL mbed

/media/uploads/kevinkeryk/avnet_logo_tagline_rgb.png

Avnet Cellular IoT Instructions

  • One problematic area is setting the MY_SERVER_URL. When you copy the URL from the flow, you must make sure the MY_SERVER_URL is also set to the appropriate server. It can be either "run-east.att.io" or "run-west.att.io".

Useful Links

Adding Additional Sensors

The FLOW_DEVICE_NAME field must contain the name of the instance of the Virtual Starter Kit in FLOW you will be communicating with. Usually this is "vstarterkit001", but if you have problems communicating you can verify this is correct. Note: This device will not be created until you click the “Initialize” input on the Virtual Device tab of the Starter Kit project in FLOW. At that point, it becomes available in M2X and you can see it as the DEVICE SERIAL field under Devices as in the image below. /media/uploads/JMF/vstarterkit.png

Sensors: When executing, the FRDM-K64F board uploads sensor measurements to AT&T’s Flow environment every 5 seconds, using the Cellular shield board. You can adjust how often you want to do this by editing the SENSOR_UPDATE_INTERVAL_MS value in the header file.

Temperature and humidity: By default, the board reports readings from the HTS221 temperature and humidity sensor. These two values are sent to the HTTP IN /climate port in FLOW with field names “temp” and “humidity”. Temperature is in degrees Fahrenheit and humidity is a %. This default assignment is: iSensorsToReport = TEMP_HUMIDITY_ONLY;

Accelerometer: If you want to expand and use the onboard motion sensor, you can also send 3-axis accelerometer information from the board as “accelX”, “accelY”, and “accelZ”. This is useful if you want to know the stationary position of the board with regards to gravity, or whether it is in motion. These readings are in g’s. To send these values, change the assignment to: iSensorsToReport = TEMP_HUMIDITY_ACCELEROMETER;

PMOD Sensors: If you have a Silicon Labs sensor module that can plug into the PMOD connector on the Cellular shield, you are able to measure proximity, UV light, ambient visible and infrared light from the Si1145 sensor. This PMOD also has a temperature and humidity sensor, but in this case it is redundant. When enabled, the fields “proximity”, “light_uv”, “light_vis” and “light_ir” are also sent. To enable all these sensors, change the assignment to: iSensorsToReport = TEMP_HUMIDITY_ACCELEROMETER_PMODSENSORS;

Connecting the PMOD sensors: Because the pinouts do not align, the SiLabs PMOD sensor board cannot be plugged into the J10 PMOD receptacle on the shield directly. The following wiring instructions must be followed:

SignalJ10ShieldPMOD Color in the image below
VCCPin 6Pin 6Red
GNDPin 5Pin 5Black
SDAPin4Pin 3Green
SCLPin3Pin 2Yellow

/media/uploads/JMF/xyz.jpg

AT&T M2X and FLOW Instructions

M2X & FLOW Instructions

Link to AT&T M2X

M2X

Link to AT&T Flow

FLOW

Avnet WNC-Shield Information

Getting Started with the Avnet WNC-Shield Software

  • This project uses Revision 119 of the MBED library because of I2C implementation differences with the tip (Revision 121).
  • This project uses Revision 4 of the FXOS8700CQ library for sensors.

Easily Modifiable Parameters

Inside the mbed Avnet_ATT_Cellular_IOT project, the parameters needed to customize your board are in the config_me.h file.

  • FLOW parameters: This project assumes you are using a fork of the Starter Kit Base project, which is a reference design created using AT&T’s FLOW (https://flow.att.com) that allows the creation of online virtualization and other IoT functionality. The default parameters in the config_me.h file are done for a specific instance of this project. When you fork the original project, you get your own instance and it will have its own base address. At the bottom of the FLOW environment, when you click on the Endpoints tab, URL information that is specific to your instance is displayed. Of note is the Base URL. In the example below (as in the default mbed project), the Base URL is: https://run-west.att.io/1e464b19cdcde/774c88d68202/86694923d5bf28a/in/flow You have to take note of two parts of this address. The run-west.att.io part is the server URL, and you have to make sure the
  • MY_SERVER_URL field in config_me.h matches this. The rest of the base URL, in green above, needs to be pasted into the FLOW_BASE_URL field.

There is also a FLOW_INPUT_NAME field. This should match the name of the HTTP IN port in the FLOW project that you want to send sensor data to. The default is "/climate", as in the FLOW image below.

/media/uploads/JMF/sf.png

Where is the Binary I compiled

When the COMPILE button is pressed, it compiles your project and links it. The result is placed in the DOWNLOAD folder you use when downloading files from the Internet. It will be called AvnetATT_shape_hackathon_K64F.bin.

Additional Information on Compiling/Configuring

Comprehensive instructions can be found at: Quick Start Instructions

Committer:
root@developer-sjc-indigo-compiler.local.mbed.org
Date:
Mon Dec 11 21:51:32 2017 +0000
Revision:
83:55778a2d5c5e
Parent:
77:c65eae5b9958
Added tag att_cellular_K64_wnc_14A2A_20171211 for changeset 65cde5d7070c

Who changed what in which revision?

UserRevisionLine numberNew contents of line
fkellermavnet 68:6e311c747045 1 /* ===================================================================
fkellermavnet 68:6e311c747045 2 Copyright © 2016, AVNET Inc.
fkellermavnet 68:6e311c747045 3
fkellermavnet 68:6e311c747045 4 Licensed under the Apache License, Version 2.0 (the "License");
fkellermavnet 68:6e311c747045 5 you may not use this file except in compliance with the License.
fkellermavnet 68:6e311c747045 6 You may obtain a copy of the License at
fkellermavnet 68:6e311c747045 7
fkellermavnet 68:6e311c747045 8 http://www.apache.org/licenses/LICENSE-2.0
fkellermavnet 68:6e311c747045 9
fkellermavnet 68:6e311c747045 10 Unless required by applicable law or agreed to in writing,
fkellermavnet 68:6e311c747045 11 software distributed under the License is distributed on an
fkellermavnet 68:6e311c747045 12 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
fkellermavnet 68:6e311c747045 13 either express or implied. See the License for the specific
fkellermavnet 68:6e311c747045 14 language governing permissions and limitations under the License.
fkellermavnet 68:6e311c747045 15
fkellermavnet 68:6e311c747045 16 ======================================================================== */
fkellermavnet 68:6e311c747045 17
stefanrousseau 55:3abf9e3f42e6 18 #include "mbed.h"
JMF 0:9d5134074d84 19 #include <cctype>
JMF 0:9d5134074d84 20 #include <string>
JMF 2:0e2ef866af95 21 #include "config_me.h"
stefanrousseau 4:f83bedd9cab4 22 #include "sensors.h"
stefanrousseau 61:f6b93129f954 23 #include "cell_modem.h"
stefanrousseau 11:e6602513730f 24 #include "hardware.h"
stefanrousseau 11:e6602513730f 25
stefanrousseau 61:f6b93129f954 26 I2C i2c(PTC11, PTC10); //SDA, SCL -- define the I2C pins being used
stefanrousseau 56:cb42ff383dab 27 MODSERIAL pc(USBTX, USBRX, 256, 256); // tx, rx with default tx, rx buffer sizes
stefanrousseau 63:90d7c69993cd 28 MODSERIAL mdm(PTD3, PTD2, 4096, 4096);
stefanrousseau 16:17c5916f2d12 29 DigitalOut led_green(LED_GREEN);
stefanrousseau 16:17c5916f2d12 30 DigitalOut led_red(LED_RED);
stefanrousseau 16:17c5916f2d12 31 DigitalOut led_blue(LED_BLUE);
JMF 0:9d5134074d84 32
JMF 0:9d5134074d84 33
stefanrousseau 3:26b3cc155f39 34 //********************************************************************************************************************************************
stefanrousseau 12:7c94ec5069dc 35 //* Create string with sensor readings that can be sent to flow as an HTTP get
stefanrousseau 3:26b3cc155f39 36 //********************************************************************************************************************************************
stefanrousseau 12:7c94ec5069dc 37 K64F_Sensors_t SENSOR_DATA =
stefanrousseau 3:26b3cc155f39 38 {
stefanrousseau 12:7c94ec5069dc 39 .Temperature = "0",
stefanrousseau 12:7c94ec5069dc 40 .Humidity = "0",
stefanrousseau 12:7c94ec5069dc 41 .AccelX = "0",
stefanrousseau 12:7c94ec5069dc 42 .AccelY = "0",
stefanrousseau 12:7c94ec5069dc 43 .AccelZ = "0",
stefanrousseau 12:7c94ec5069dc 44 .MagnetometerX = "0",
stefanrousseau 12:7c94ec5069dc 45 .MagnetometerY = "0",
stefanrousseau 12:7c94ec5069dc 46 .MagnetometerZ = "0",
stefanrousseau 12:7c94ec5069dc 47 .AmbientLightVis = "0",
stefanrousseau 12:7c94ec5069dc 48 .AmbientLightIr = "0",
stefanrousseau 12:7c94ec5069dc 49 .UVindex = "0",
stefanrousseau 12:7c94ec5069dc 50 .Proximity = "0",
stefanrousseau 12:7c94ec5069dc 51 .Temperature_Si7020 = "0",
stefanrousseau 55:3abf9e3f42e6 52 .Humidity_Si7020 = "0",
stefanrousseau 55:3abf9e3f42e6 53 .Virtual_Sensor1 = "0",
stefanrousseau 55:3abf9e3f42e6 54 .Virtual_Sensor2 = "0",
stefanrousseau 55:3abf9e3f42e6 55 .Virtual_Sensor3 = "0",
stefanrousseau 55:3abf9e3f42e6 56 .Virtual_Sensor4 = "0",
stefanrousseau 55:3abf9e3f42e6 57 .Virtual_Sensor5 = "0",
stefanrousseau 55:3abf9e3f42e6 58 .Virtual_Sensor6 = "0",
stefanrousseau 55:3abf9e3f42e6 59 .Virtual_Sensor7 = "0",
stefanrousseau 71:45a5e426df81 60 .Virtual_Sensor8 = "0",
stefanrousseau 72:b500e1507b5f 61 .GPS_Satellites = "0",
stefanrousseau 71:45a5e426df81 62 .GPS_Latitude = "0",
stefanrousseau 71:45a5e426df81 63 .GPS_Longitude = "0",
stefanrousseau 71:45a5e426df81 64 .GPS_Altitude = "0",
stefanrousseau 71:45a5e426df81 65 .GPS_Speed = "0",
stefanrousseau 71:45a5e426df81 66 .GPS_Course = "0"
stefanrousseau 3:26b3cc155f39 67 };
stefanrousseau 12:7c94ec5069dc 68
fkellermavnet 77:c65eae5b9958 69 void display_app_firmware_version(void)
fkellermavnet 77:c65eae5b9958 70 {
fkellermavnet 77:c65eae5b9958 71 PUTS("\r\n\r\nApp Firmware: Release 1.0 - built: "__DATE__" "__TIME__"\r\n\r\n");
fkellermavnet 77:c65eae5b9958 72 }
fkellermavnet 77:c65eae5b9958 73
stefanrousseau 3:26b3cc155f39 74 void GenerateModemString(char * modem_string)
stefanrousseau 3:26b3cc155f39 75 {
stefanrousseau 12:7c94ec5069dc 76 switch(iSensorsToReport)
stefanrousseau 12:7c94ec5069dc 77 {
stefanrousseau 12:7c94ec5069dc 78 case TEMP_HUMIDITY_ONLY:
stefanrousseau 12:7c94ec5069dc 79 {
stefanrousseau 12:7c94ec5069dc 80 sprintf(modem_string, "GET %s%s?serial=%s&temp=%s&humidity=%s %s%s\r\n\r\n", FLOW_BASE_URL, FLOW_INPUT_NAME, FLOW_DEVICE_NAME, SENSOR_DATA.Temperature, SENSOR_DATA.Humidity, FLOW_URL_TYPE, MY_SERVER_URL);
stefanrousseau 12:7c94ec5069dc 81 break;
stefanrousseau 12:7c94ec5069dc 82 }
stefanrousseau 12:7c94ec5069dc 83 case TEMP_HUMIDITY_ACCELEROMETER:
stefanrousseau 12:7c94ec5069dc 84 {
stefanrousseau 12:7c94ec5069dc 85 sprintf(modem_string, "GET %s%s?serial=%s&temp=%s&humidity=%s&accelX=%s&accelY=%s&accelZ=%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, FLOW_URL_TYPE, MY_SERVER_URL);
stefanrousseau 12:7c94ec5069dc 86 break;
stefanrousseau 12:7c94ec5069dc 87 }
stefanrousseau 70:24d5800f27be 88 case TEMP_HUMIDITY_ACCELEROMETER_GPS:
stefanrousseau 70:24d5800f27be 89 {
stefanrousseau 72:b500e1507b5f 90 sprintf(modem_string, "GET %s%s?serial=%s&temp=%s&humidity=%s&accelX=%s&accelY=%s&accelZ=%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.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);
stefanrousseau 70:24d5800f27be 91 break;
stefanrousseau 70:24d5800f27be 92 }
stefanrousseau 12:7c94ec5069dc 93 case TEMP_HUMIDITY_ACCELEROMETER_PMODSENSORS:
stefanrousseau 12:7c94ec5069dc 94 {
stefanrousseau 12:7c94ec5069dc 95 sprintf(modem_string, "GET %s%s?serial=%s&temp=%s&humidity=%s&accelX=%s&accelY=%s&accelZ=%s&proximity=%s&light_uv=%s&light_vis=%s&light_ir=%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.Proximity, SENSOR_DATA.UVindex, SENSOR_DATA.AmbientLightVis, SENSOR_DATA.AmbientLightIr, FLOW_URL_TYPE, MY_SERVER_URL);
stefanrousseau 12:7c94ec5069dc 96 break;
stefanrousseau 12:7c94ec5069dc 97 }
stefanrousseau 55:3abf9e3f42e6 98 case TEMP_HUMIDITY_ACCELEROMETER_PMODSENSORS_VIRTUALSENSORS:
stefanrousseau 55:3abf9e3f42e6 99 {
stefanrousseau 55:3abf9e3f42e6 100 sprintf(modem_string, "GET %s%s?serial=%s&temp=%s&humidity=%s&accelX=%s&accelY=%s&accelZ=%s&proximity=%s&light_uv=%s&light_vis=%s&light_ir=%s&virt_sens1=%s&virt_sens2=%s&virt_sens3=%s&virt_sens4=%s&virt_sens5=%s&virt_sens6=%s&virt_sens7=%s&virt_sens8=%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.Proximity, SENSOR_DATA.UVindex, SENSOR_DATA.AmbientLightVis, SENSOR_DATA.AmbientLightIr, SENSOR_DATA.Virtual_Sensor1, SENSOR_DATA.Virtual_Sensor2, SENSOR_DATA.Virtual_Sensor3, SENSOR_DATA.Virtual_Sensor4, SENSOR_DATA.Virtual_Sensor5, SENSOR_DATA.Virtual_Sensor6, SENSOR_DATA.Virtual_Sensor7, SENSOR_DATA.Virtual_Sensor8, FLOW_URL_TYPE, MY_SERVER_URL);
stefanrousseau 55:3abf9e3f42e6 101 break;
stefanrousseau 55:3abf9e3f42e6 102 }
stefanrousseau 12:7c94ec5069dc 103 default:
stefanrousseau 12:7c94ec5069dc 104 {
stefanrousseau 12:7c94ec5069dc 105 sprintf(modem_string, "Invalid sensor selected\r\n\r\n");
stefanrousseau 12:7c94ec5069dc 106 break;
stefanrousseau 12:7c94ec5069dc 107 }
stefanrousseau 16:17c5916f2d12 108 } //switch(iSensorsToReport)
stefanrousseau 3:26b3cc155f39 109 } //GenerateModemString
stefanrousseau 3:26b3cc155f39 110
stefanrousseau 3:26b3cc155f39 111
stefanrousseau 3:26b3cc155f39 112 //Periodic timer
stefanrousseau 3:26b3cc155f39 113 Ticker OneMsTicker;
stefanrousseau 3:26b3cc155f39 114 volatile bool bTimerExpiredFlag = false;
stefanrousseau 3:26b3cc155f39 115 int OneMsTicks = 0;
stefanrousseau 3:26b3cc155f39 116 int iTimer1Interval_ms = 1000;
stefanrousseau 3:26b3cc155f39 117 //********************************************************************************************************************************************
stefanrousseau 3:26b3cc155f39 118 //* Periodic 1ms timer tick
stefanrousseau 3:26b3cc155f39 119 //********************************************************************************************************************************************
stefanrousseau 3:26b3cc155f39 120 void OneMsFunction()
stefanrousseau 3:26b3cc155f39 121 {
stefanrousseau 3:26b3cc155f39 122 OneMsTicks++;
stefanrousseau 3:26b3cc155f39 123 if ((OneMsTicks % iTimer1Interval_ms) == 0)
stefanrousseau 3:26b3cc155f39 124 {
stefanrousseau 3:26b3cc155f39 125 bTimerExpiredFlag = true;
stefanrousseau 3:26b3cc155f39 126 }
stefanrousseau 3:26b3cc155f39 127 } //OneMsFunction()
stefanrousseau 3:26b3cc155f39 128
stefanrousseau 16:17c5916f2d12 129 //********************************************************************************************************************************************
stefanrousseau 16:17c5916f2d12 130 //* Set the RGB LED's Color
stefanrousseau 16:17c5916f2d12 131 //* LED Color 0=Off to 7=White. 3 bits represent BGR (bit0=Red, bit1=Green, bit2=Blue)
stefanrousseau 16:17c5916f2d12 132 //********************************************************************************************************************************************
stefanrousseau 16:17c5916f2d12 133 void SetLedColor(unsigned char ucColor)
stefanrousseau 16:17c5916f2d12 134 {
stefanrousseau 16:17c5916f2d12 135 //Note that when an LED is on, you write a 0 to it:
stefanrousseau 16:17c5916f2d12 136 led_red = !(ucColor & 0x1); //bit 0
stefanrousseau 16:17c5916f2d12 137 led_green = !(ucColor & 0x2); //bit 1
stefanrousseau 16:17c5916f2d12 138 led_blue = !(ucColor & 0x4); //bit 2
stefanrousseau 16:17c5916f2d12 139 } //SetLedColor()
stefanrousseau 16:17c5916f2d12 140
stefanrousseau 16:17c5916f2d12 141 //********************************************************************************************************************************************
stefanrousseau 61:f6b93129f954 142 //* Process the JSON response. In this example we are only extracting a LED color.
stefanrousseau 16:17c5916f2d12 143 //********************************************************************************************************************************************
stefanrousseau 16:17c5916f2d12 144 bool parse_JSON(char* json_string)
stefanrousseau 16:17c5916f2d12 145 {
stefanrousseau 16:17c5916f2d12 146 char* beginquote;
stefanrousseau 16:17c5916f2d12 147 char token[] = "\"LED\":\"";
stefanrousseau 16:17c5916f2d12 148 beginquote = strstr(json_string, token );
stefanrousseau 16:17c5916f2d12 149 if ((beginquote != 0))
stefanrousseau 16:17c5916f2d12 150 {
stefanrousseau 16:17c5916f2d12 151 char cLedColor = beginquote[strlen(token)];
stefanrousseau 64:09004cd610df 152 PRINTF(GRN "LED Found : %c" DEF "\r\n", cLedColor);
stefanrousseau 16:17c5916f2d12 153 switch(cLedColor)
stefanrousseau 16:17c5916f2d12 154 {
stefanrousseau 16:17c5916f2d12 155 case 'O':
stefanrousseau 16:17c5916f2d12 156 { //Off
stefanrousseau 16:17c5916f2d12 157 SetLedColor(0);
stefanrousseau 16:17c5916f2d12 158 break;
stefanrousseau 16:17c5916f2d12 159 }
stefanrousseau 16:17c5916f2d12 160 case 'R':
stefanrousseau 16:17c5916f2d12 161 { //Red
stefanrousseau 16:17c5916f2d12 162 SetLedColor(1);
stefanrousseau 16:17c5916f2d12 163 break;
stefanrousseau 16:17c5916f2d12 164 }
stefanrousseau 16:17c5916f2d12 165 case 'G':
stefanrousseau 16:17c5916f2d12 166 { //Green
stefanrousseau 16:17c5916f2d12 167 SetLedColor(2);
stefanrousseau 16:17c5916f2d12 168 break;
stefanrousseau 16:17c5916f2d12 169 }
stefanrousseau 16:17c5916f2d12 170 case 'Y':
stefanrousseau 16:17c5916f2d12 171 { //Yellow
stefanrousseau 16:17c5916f2d12 172 SetLedColor(3);
stefanrousseau 16:17c5916f2d12 173 break;
stefanrousseau 16:17c5916f2d12 174 }
stefanrousseau 16:17c5916f2d12 175 case 'B':
stefanrousseau 16:17c5916f2d12 176 { //Blue
stefanrousseau 16:17c5916f2d12 177 SetLedColor(4);
stefanrousseau 16:17c5916f2d12 178 break;
stefanrousseau 16:17c5916f2d12 179 }
stefanrousseau 16:17c5916f2d12 180 case 'M':
stefanrousseau 16:17c5916f2d12 181 { //Magenta
stefanrousseau 16:17c5916f2d12 182 SetLedColor(5);
stefanrousseau 16:17c5916f2d12 183 break;
stefanrousseau 16:17c5916f2d12 184 }
stefanrousseau 16:17c5916f2d12 185 case 'T':
stefanrousseau 16:17c5916f2d12 186 { //Turquoise
stefanrousseau 16:17c5916f2d12 187 SetLedColor(6);
stefanrousseau 16:17c5916f2d12 188 break;
stefanrousseau 16:17c5916f2d12 189 }
stefanrousseau 16:17c5916f2d12 190 case 'W':
stefanrousseau 16:17c5916f2d12 191 { //White
stefanrousseau 16:17c5916f2d12 192 SetLedColor(7);
stefanrousseau 16:17c5916f2d12 193 break;
stefanrousseau 16:17c5916f2d12 194 }
stefanrousseau 16:17c5916f2d12 195 default:
stefanrousseau 16:17c5916f2d12 196 {
stefanrousseau 16:17c5916f2d12 197 break;
stefanrousseau 16:17c5916f2d12 198 }
stefanrousseau 16:17c5916f2d12 199 } //switch(cLedColor)
stefanrousseau 16:17c5916f2d12 200 return true;
stefanrousseau 16:17c5916f2d12 201 }
stefanrousseau 16:17c5916f2d12 202 else
stefanrousseau 16:17c5916f2d12 203 {
stefanrousseau 16:17c5916f2d12 204 return false;
stefanrousseau 16:17c5916f2d12 205 }
stefanrousseau 16:17c5916f2d12 206 } //parse_JSON
stefanrousseau 16:17c5916f2d12 207
JMF 0:9d5134074d84 208 int main() {
stefanrousseau 61:f6b93129f954 209 static unsigned ledOnce = 0;
stefanrousseau 72:b500e1507b5f 210 //delay so that the debug terminal can open after power-on reset:
fkellermavnet 77:c65eae5b9958 211 wait (5.0);
stefanrousseau 61:f6b93129f954 212 pc.baud(115200);
fkellermavnet 77:c65eae5b9958 213
fkellermavnet 77:c65eae5b9958 214 display_app_firmware_version();
fkellermavnet 77:c65eae5b9958 215
stefanrousseau 64:09004cd610df 216 PRINTF(GRN "Hello World from the Cellular IoT Kit!\r\n\r\n");
JMF 0:9d5134074d84 217
stefanrousseau 61:f6b93129f954 218 //Initialize the I2C sensors that are present
stefanrousseau 11:e6602513730f 219 sensors_init();
stefanrousseau 12:7c94ec5069dc 220 read_sensors();
stefanrousseau 11:e6602513730f 221
stefanrousseau 61:f6b93129f954 222 // Set LED to RED until init finishes
stefanrousseau 61:f6b93129f954 223 SetLedColor(0x1); //Red
JMF 0:9d5134074d84 224 // Initialize the modem
stefanrousseau 64:09004cd610df 225 PRINTF("\r\n");
stefanrousseau 61:f6b93129f954 226 cell_modem_init();
fkellermavnet 77:c65eae5b9958 227 display_wnc_firmware_rev();
fkellermavnet 77:c65eae5b9958 228
stefanrousseau 61:f6b93129f954 229 // Set LED BLUE for partial init
stefanrousseau 61:f6b93129f954 230 SetLedColor(0x4); //Blue
JMF 0:9d5134074d84 231
stefanrousseau 3:26b3cc155f39 232 //Create a 1ms timer tick function:
stefanrousseau 61:f6b93129f954 233 iTimer1Interval_ms = SENSOR_UPDATE_INTERVAL_MS;
stefanrousseau 3:26b3cc155f39 234 OneMsTicker.attach(OneMsFunction, 0.001f) ;
fkellermavnet 26:8d6e7e7cdcae 235
JMF 2:0e2ef866af95 236 // Send and receive data perpetually
JMF 2:0e2ef866af95 237 while(1) {
stefanrousseau 55:3abf9e3f42e6 238 #ifdef USE_VIRTUAL_SENSORS
stefanrousseau 55:3abf9e3f42e6 239 ProcessUsbInterface();
stefanrousseau 55:3abf9e3f42e6 240 #endif
stefanrousseau 3:26b3cc155f39 241 if (bTimerExpiredFlag)
stefanrousseau 3:26b3cc155f39 242 {
stefanrousseau 3:26b3cc155f39 243 bTimerExpiredFlag = false;
stefanrousseau 4:f83bedd9cab4 244 read_sensors(); //read available external sensors from a PMOD and the on-board motion sensor
stefanrousseau 3:26b3cc155f39 245 char modem_string[512];
stefanrousseau 3:26b3cc155f39 246 GenerateModemString(&modem_string[0]);
stefanrousseau 61:f6b93129f954 247 char myJsonResponse[512];
stefanrousseau 61:f6b93129f954 248 if (cell_modem_Sendreceive(&modem_string[0], &myJsonResponse[0]))
fkellermavnet 20:27a4f27254d0 249 {
stefanrousseau 41:9b14c40eebf6 250 if (!ledOnce)
stefanrousseau 41:9b14c40eebf6 251 {
stefanrousseau 41:9b14c40eebf6 252 ledOnce = 1;
stefanrousseau 61:f6b93129f954 253 SetLedColor(0x2); //Green
stefanrousseau 41:9b14c40eebf6 254 }
stefanrousseau 61:f6b93129f954 255 parse_JSON(&myJsonResponse[0]);
stefanrousseau 16:17c5916f2d12 256 }
stefanrousseau 3:26b3cc155f39 257 } //bTimerExpiredFlag
stefanrousseau 3:26b3cc155f39 258 } //forever loop
JMF 0:9d5134074d84 259 }