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:
stefanrousseau
Date:
Thu Aug 11 21:14:32 2016 +0000
Revision:
72:b500e1507b5f
Parent:
71:45a5e426df81
Child:
77:c65eae5b9958
Add 4s startup delay and changed GPS_valid to number of satellites.

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
stefanrousseau 3:26b3cc155f39 69 void GenerateModemString(char * modem_string)
stefanrousseau 3:26b3cc155f39 70 {
stefanrousseau 12:7c94ec5069dc 71 switch(iSensorsToReport)
stefanrousseau 12:7c94ec5069dc 72 {
stefanrousseau 12:7c94ec5069dc 73 case TEMP_HUMIDITY_ONLY:
stefanrousseau 12:7c94ec5069dc 74 {
stefanrousseau 12:7c94ec5069dc 75 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 76 break;
stefanrousseau 12:7c94ec5069dc 77 }
stefanrousseau 12:7c94ec5069dc 78 case TEMP_HUMIDITY_ACCELEROMETER:
stefanrousseau 12:7c94ec5069dc 79 {
stefanrousseau 12:7c94ec5069dc 80 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 81 break;
stefanrousseau 12:7c94ec5069dc 82 }
stefanrousseau 70:24d5800f27be 83 case TEMP_HUMIDITY_ACCELEROMETER_GPS:
stefanrousseau 70:24d5800f27be 84 {
stefanrousseau 72:b500e1507b5f 85 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 86 break;
stefanrousseau 70:24d5800f27be 87 }
stefanrousseau 12:7c94ec5069dc 88 case TEMP_HUMIDITY_ACCELEROMETER_PMODSENSORS:
stefanrousseau 12:7c94ec5069dc 89 {
stefanrousseau 12:7c94ec5069dc 90 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 91 break;
stefanrousseau 12:7c94ec5069dc 92 }
stefanrousseau 55:3abf9e3f42e6 93 case TEMP_HUMIDITY_ACCELEROMETER_PMODSENSORS_VIRTUALSENSORS:
stefanrousseau 55:3abf9e3f42e6 94 {
stefanrousseau 55:3abf9e3f42e6 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&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 96 break;
stefanrousseau 55:3abf9e3f42e6 97 }
stefanrousseau 12:7c94ec5069dc 98 default:
stefanrousseau 12:7c94ec5069dc 99 {
stefanrousseau 12:7c94ec5069dc 100 sprintf(modem_string, "Invalid sensor selected\r\n\r\n");
stefanrousseau 12:7c94ec5069dc 101 break;
stefanrousseau 12:7c94ec5069dc 102 }
stefanrousseau 16:17c5916f2d12 103 } //switch(iSensorsToReport)
stefanrousseau 3:26b3cc155f39 104 } //GenerateModemString
stefanrousseau 3:26b3cc155f39 105
stefanrousseau 3:26b3cc155f39 106
stefanrousseau 3:26b3cc155f39 107 //Periodic timer
stefanrousseau 3:26b3cc155f39 108 Ticker OneMsTicker;
stefanrousseau 3:26b3cc155f39 109 volatile bool bTimerExpiredFlag = false;
stefanrousseau 3:26b3cc155f39 110 int OneMsTicks = 0;
stefanrousseau 3:26b3cc155f39 111 int iTimer1Interval_ms = 1000;
stefanrousseau 3:26b3cc155f39 112 //********************************************************************************************************************************************
stefanrousseau 3:26b3cc155f39 113 //* Periodic 1ms timer tick
stefanrousseau 3:26b3cc155f39 114 //********************************************************************************************************************************************
stefanrousseau 3:26b3cc155f39 115 void OneMsFunction()
stefanrousseau 3:26b3cc155f39 116 {
stefanrousseau 3:26b3cc155f39 117 OneMsTicks++;
stefanrousseau 3:26b3cc155f39 118 if ((OneMsTicks % iTimer1Interval_ms) == 0)
stefanrousseau 3:26b3cc155f39 119 {
stefanrousseau 3:26b3cc155f39 120 bTimerExpiredFlag = true;
stefanrousseau 3:26b3cc155f39 121 }
stefanrousseau 3:26b3cc155f39 122 } //OneMsFunction()
stefanrousseau 3:26b3cc155f39 123
stefanrousseau 16:17c5916f2d12 124 //********************************************************************************************************************************************
stefanrousseau 16:17c5916f2d12 125 //* Set the RGB LED's Color
stefanrousseau 16:17c5916f2d12 126 //* LED Color 0=Off to 7=White. 3 bits represent BGR (bit0=Red, bit1=Green, bit2=Blue)
stefanrousseau 16:17c5916f2d12 127 //********************************************************************************************************************************************
stefanrousseau 16:17c5916f2d12 128 void SetLedColor(unsigned char ucColor)
stefanrousseau 16:17c5916f2d12 129 {
stefanrousseau 16:17c5916f2d12 130 //Note that when an LED is on, you write a 0 to it:
stefanrousseau 16:17c5916f2d12 131 led_red = !(ucColor & 0x1); //bit 0
stefanrousseau 16:17c5916f2d12 132 led_green = !(ucColor & 0x2); //bit 1
stefanrousseau 16:17c5916f2d12 133 led_blue = !(ucColor & 0x4); //bit 2
stefanrousseau 16:17c5916f2d12 134 } //SetLedColor()
stefanrousseau 16:17c5916f2d12 135
stefanrousseau 16:17c5916f2d12 136 //********************************************************************************************************************************************
stefanrousseau 61:f6b93129f954 137 //* Process the JSON response. In this example we are only extracting a LED color.
stefanrousseau 16:17c5916f2d12 138 //********************************************************************************************************************************************
stefanrousseau 16:17c5916f2d12 139 bool parse_JSON(char* json_string)
stefanrousseau 16:17c5916f2d12 140 {
stefanrousseau 16:17c5916f2d12 141 char* beginquote;
stefanrousseau 16:17c5916f2d12 142 char token[] = "\"LED\":\"";
stefanrousseau 16:17c5916f2d12 143 beginquote = strstr(json_string, token );
stefanrousseau 16:17c5916f2d12 144 if ((beginquote != 0))
stefanrousseau 16:17c5916f2d12 145 {
stefanrousseau 16:17c5916f2d12 146 char cLedColor = beginquote[strlen(token)];
stefanrousseau 64:09004cd610df 147 PRINTF(GRN "LED Found : %c" DEF "\r\n", cLedColor);
stefanrousseau 16:17c5916f2d12 148 switch(cLedColor)
stefanrousseau 16:17c5916f2d12 149 {
stefanrousseau 16:17c5916f2d12 150 case 'O':
stefanrousseau 16:17c5916f2d12 151 { //Off
stefanrousseau 16:17c5916f2d12 152 SetLedColor(0);
stefanrousseau 16:17c5916f2d12 153 break;
stefanrousseau 16:17c5916f2d12 154 }
stefanrousseau 16:17c5916f2d12 155 case 'R':
stefanrousseau 16:17c5916f2d12 156 { //Red
stefanrousseau 16:17c5916f2d12 157 SetLedColor(1);
stefanrousseau 16:17c5916f2d12 158 break;
stefanrousseau 16:17c5916f2d12 159 }
stefanrousseau 16:17c5916f2d12 160 case 'G':
stefanrousseau 16:17c5916f2d12 161 { //Green
stefanrousseau 16:17c5916f2d12 162 SetLedColor(2);
stefanrousseau 16:17c5916f2d12 163 break;
stefanrousseau 16:17c5916f2d12 164 }
stefanrousseau 16:17c5916f2d12 165 case 'Y':
stefanrousseau 16:17c5916f2d12 166 { //Yellow
stefanrousseau 16:17c5916f2d12 167 SetLedColor(3);
stefanrousseau 16:17c5916f2d12 168 break;
stefanrousseau 16:17c5916f2d12 169 }
stefanrousseau 16:17c5916f2d12 170 case 'B':
stefanrousseau 16:17c5916f2d12 171 { //Blue
stefanrousseau 16:17c5916f2d12 172 SetLedColor(4);
stefanrousseau 16:17c5916f2d12 173 break;
stefanrousseau 16:17c5916f2d12 174 }
stefanrousseau 16:17c5916f2d12 175 case 'M':
stefanrousseau 16:17c5916f2d12 176 { //Magenta
stefanrousseau 16:17c5916f2d12 177 SetLedColor(5);
stefanrousseau 16:17c5916f2d12 178 break;
stefanrousseau 16:17c5916f2d12 179 }
stefanrousseau 16:17c5916f2d12 180 case 'T':
stefanrousseau 16:17c5916f2d12 181 { //Turquoise
stefanrousseau 16:17c5916f2d12 182 SetLedColor(6);
stefanrousseau 16:17c5916f2d12 183 break;
stefanrousseau 16:17c5916f2d12 184 }
stefanrousseau 16:17c5916f2d12 185 case 'W':
stefanrousseau 16:17c5916f2d12 186 { //White
stefanrousseau 16:17c5916f2d12 187 SetLedColor(7);
stefanrousseau 16:17c5916f2d12 188 break;
stefanrousseau 16:17c5916f2d12 189 }
stefanrousseau 16:17c5916f2d12 190 default:
stefanrousseau 16:17c5916f2d12 191 {
stefanrousseau 16:17c5916f2d12 192 break;
stefanrousseau 16:17c5916f2d12 193 }
stefanrousseau 16:17c5916f2d12 194 } //switch(cLedColor)
stefanrousseau 16:17c5916f2d12 195 return true;
stefanrousseau 16:17c5916f2d12 196 }
stefanrousseau 16:17c5916f2d12 197 else
stefanrousseau 16:17c5916f2d12 198 {
stefanrousseau 16:17c5916f2d12 199 return false;
stefanrousseau 16:17c5916f2d12 200 }
stefanrousseau 16:17c5916f2d12 201 } //parse_JSON
stefanrousseau 16:17c5916f2d12 202
JMF 0:9d5134074d84 203 int main() {
stefanrousseau 61:f6b93129f954 204 static unsigned ledOnce = 0;
stefanrousseau 72:b500e1507b5f 205 //delay so that the debug terminal can open after power-on reset:
stefanrousseau 72:b500e1507b5f 206 wait (4.0);
stefanrousseau 61:f6b93129f954 207 pc.baud(115200);
stefanrousseau 64:09004cd610df 208 PRINTF(GRN "Hello World from the Cellular IoT Kit!\r\n\r\n");
JMF 0:9d5134074d84 209
stefanrousseau 61:f6b93129f954 210 //Initialize the I2C sensors that are present
stefanrousseau 11:e6602513730f 211 sensors_init();
stefanrousseau 12:7c94ec5069dc 212 read_sensors();
stefanrousseau 11:e6602513730f 213
stefanrousseau 61:f6b93129f954 214 // Set LED to RED until init finishes
stefanrousseau 61:f6b93129f954 215 SetLedColor(0x1); //Red
JMF 0:9d5134074d84 216 // Initialize the modem
stefanrousseau 64:09004cd610df 217 PRINTF("\r\n");
stefanrousseau 61:f6b93129f954 218 cell_modem_init();
stefanrousseau 61:f6b93129f954 219 // Set LED BLUE for partial init
stefanrousseau 61:f6b93129f954 220 SetLedColor(0x4); //Blue
JMF 0:9d5134074d84 221
stefanrousseau 3:26b3cc155f39 222 //Create a 1ms timer tick function:
stefanrousseau 61:f6b93129f954 223 iTimer1Interval_ms = SENSOR_UPDATE_INTERVAL_MS;
stefanrousseau 3:26b3cc155f39 224 OneMsTicker.attach(OneMsFunction, 0.001f) ;
fkellermavnet 26:8d6e7e7cdcae 225
JMF 2:0e2ef866af95 226 // Send and receive data perpetually
JMF 2:0e2ef866af95 227 while(1) {
stefanrousseau 55:3abf9e3f42e6 228 #ifdef USE_VIRTUAL_SENSORS
stefanrousseau 55:3abf9e3f42e6 229 ProcessUsbInterface();
stefanrousseau 55:3abf9e3f42e6 230 #endif
stefanrousseau 3:26b3cc155f39 231 if (bTimerExpiredFlag)
stefanrousseau 3:26b3cc155f39 232 {
stefanrousseau 3:26b3cc155f39 233 bTimerExpiredFlag = false;
stefanrousseau 4:f83bedd9cab4 234 read_sensors(); //read available external sensors from a PMOD and the on-board motion sensor
stefanrousseau 3:26b3cc155f39 235 char modem_string[512];
stefanrousseau 3:26b3cc155f39 236 GenerateModemString(&modem_string[0]);
stefanrousseau 61:f6b93129f954 237 char myJsonResponse[512];
stefanrousseau 61:f6b93129f954 238 if (cell_modem_Sendreceive(&modem_string[0], &myJsonResponse[0]))
fkellermavnet 20:27a4f27254d0 239 {
stefanrousseau 41:9b14c40eebf6 240 if (!ledOnce)
stefanrousseau 41:9b14c40eebf6 241 {
stefanrousseau 41:9b14c40eebf6 242 ledOnce = 1;
stefanrousseau 61:f6b93129f954 243 SetLedColor(0x2); //Green
stefanrousseau 41:9b14c40eebf6 244 }
stefanrousseau 61:f6b93129f954 245 parse_JSON(&myJsonResponse[0]);
stefanrousseau 16:17c5916f2d12 246 }
stefanrousseau 3:26b3cc155f39 247 } //bTimerExpiredFlag
stefanrousseau 3:26b3cc155f39 248 } //forever loop
JMF 0:9d5134074d84 249 }