itbrainpower.net
THE ALPHABET PROJECT - professional Arduino, BeagleBone & Raspberry PI shields


Pre-order xyz-mIoT shield first integrated IoT sensors platform w. LPWR LTE modem. 20% discount!

LTE CATM1 or GSM temperature and humidity IOT CLOUD monitoring using xyz-mIOT

 

LTE CATM1 or GSM temperature and humidity IOT CLOUD monitoring using xyz-mIOT :: how to

 

About project

LTE CATM1 or GSM temperature and humidity IOT CLOUD monitoring using xyz-mIOT :: xyz-mIOT equipped with BG96, top side - size representation
Use of-the-self xyz-mIOT shield temperature and humidity sensors as CLOUD sensor data loggers. T minus 15 minutes.

At April 08th 2018, R&D Software Solutions srl [itbrainpower.net] revealed to the public the announcement of the xyz-mIoT by itbrainpower.net shield - the first, and the most compact, IoT board that combines the versatility of ARM0 micro-controller (Microchip/Atmel ATSAMD21G in Arduino Zero compatible design), the comfortable use of the embedded sensors bundle with conectivity provided by LPWR LTE CAT M1 or NB-IoT long-range & low-power modems or legacy 3G / GSM modems.

The xyz-mIoT shield may have up to 5 integrated sensors, as: THS (temperature and humidity sensors) - HDC2010, tVOC & eCO2 (air quality sensor - CO2 total volatile organic compounds- CO2 equivalent) - CCS811 , HALL (magnetic sensor) - DRV5032 sau or IR (infrared sensor) KP-2012P3C , secondary IR (infrared sensor) - KP-2012P3C , TILT (movement vibration sensor) or REED (magnetic sensor) - SW200D.
Embedded sensors that populates the xyz-mIoT shield are dependent on PN ordered (check here for available PN).

Required time: 10-15 minutes.
The implementation time may vary depending on previous user experience. Arduino environment installing and manual Arduino class installing are not covered by this how to; try google it. Support libraries and the source code used in this how to are available for download, for registered users here.

Difficulty: beginner - intermediate.

 

Bill of materials

  • xyz-mIoT shield having integrated HDC2010 sensor, as following PN:
    XYZMIOT209#BG96-UFL-1100000 [LTE CAT M1 and GSM modem],
    or
    XYZMIOT209#M95FA-UFL-1100000 [GSM only modem]
  • micro-sze [4FF] LTE CATM1 or 2G SIM card [having data plan enabled]
  • small LiPo battery
  • GSM embedded antenna with uFL [check xyz-mIoT accesories] or,
  • GSM antenna with SMA plus u.FL to SMA pigtail [check xyz-mIoT accesories]

 

Step1 [hardware, soldering]:

LTE CATM1 or GSM temperature and humidity IOT CLOUD monitoring using xyz-mIOT :: xyz-mIoT via USB powering

Enable 5V from USB to be as primary power supply for the board as described up here. Alternative: solder both connectors rows, place the board into one breadboard and connect between Vusb and Vraw using one male-male breadboard wire.

Solder the LiPo connector. Keep in mind the LiPO polarity!

DOUBLE CHECK YOUR SOLDERINGS!!!.

 

Step2 [hardware, bring all together]:

Insert the micro-SIM in his slot [the SIM must have the PIN check procedure removed]. Connect the antenna, then connect the USB cable to xyz-mIoT USB port and to your computer. Connect the LiPo battery. LTE CATM1 or GSM temperature and humidity IOT CLOUD monitoring using xyz-mIOT :: all hardware wired together

 

Step 3 [software download and install, preliminarii settings]

a. Download and install "xyz-mIoT shields Arduino class", then download the last version of classes: "xyz-mIOT shield IoT Rest support" and "xyz-mIOT shield sensors support class" from here.
b. Install the classes. Uncompress the archives and install the classes - in a nutshell:
- copy the "xyz-mIoT shields Arduino class" files in Arduino local hardware folder (mine is: "C:\Users\dragos\Documents\Arduino\hardware"), then
- copy the the support classes folders into your Arduino local user folder [mine is: "C:\Users\dragos\Documents\Arduino\libraries"] and
- restart Arduino environment.
More detail about manual library installing, read Arduino library manual installation.

c. Make a folder named "xyz_mIoT_v41_temp_humidity".

d. Copy the code bellow, paste it one new file and save the file as "xyz_mIoT_v41_temp_humidity.ino" in the folder created in previous step. Alternate, you can download from here (right click & save as):
LTE CATM1 or GSM temperature and humidity IOT CLOUD monitoring using xyz-mIOT - Arduino main code

xyz_mIoT_v41_temp_humidity.ino

1/*
2xyz_mIoT_cloud_demo.ino v 0.41/20180217 - SOFTWARE EXAMPLE
3COPYRIGHT (c) 2015-2018 Dragos Iosub / R&D Software Solutions srl
4
5You are legaly entitled to use this SOFTWARE ONLY IN CONJUNCTION WITH xyz-mIOT by itbrainpower.net DEVICES USAGE. Modifications, derivates and 
6redistribution of this software must include unmodified this COPYRIGHT NOTICE. You can redistribute this SOFTWARE and/or modify it under the terms 
7of this COPYRIGHT NOTICE. Any other usage may be permited only after written notice of Dragos Iosub / R&D Software Solutions srl.
8
9This SOFTWARE is distributed is provide "AS IS" in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 
10warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
12Dragos Iosub, Bucharest 2018.
13https://itbrainpower.net
14*/
15#define cloudURL        "http://iot.robofun.ro/api/v1/senzor/"
16#define sensorValURL    "/input?value="
17#define tempTocken      ""    //replace with your temperature sensor tocken
18#define humiTocken      ""    //replace with your humidity sensor tocken
19
20int samplingPeriod = 60;       //interval in seconds between scans... keep it > 60 sec
21
22/*local vars, sensors and actuators exchanged with the cloud*/
23//char dttime [31];
24char IMEI [16];  
25double temperature = 0;
26double humidity = 0;
27//int alarmTHS = 0;
28//int alarmHALL = 0;
29/*local vars, sensors and actuators exchanged with the cloud*/
30
31
32#include <itbpGSMClassINST.h>
33
34#define DEBUG(x)    {__itbpDebugPort__.print(millis());__itbpDebugPort__.print(" - ");__itbpDebugPort__.println(x);}
35#define DEBUGP(x,y) {__itbpDebugPort__.print(millis());__itbpDebugPort__.print(" - ");__itbpDebugPort__.print(x);__itbpDebugPort__.println(y);}
36
37#if (__itbpModem__ != xyzmIoT)
38  int freeRam () {
39    extern int __heap_start, *__brkval; 
40    int v; 
41    return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval); 
42  }
43#endif
44
45// initialize the library instance
46aGsmClient client;
47
48
49/* sensor side here */
50//I2C THS HDC2010 from Texas [option for xyz-mIoT]
51#include <HDC2010.h>
52#define ADDRTHS 0x40
53#define ALERTTHSPIN 5
54#define ALERTHALLPIN 6
55#define ENABLEHALL 8
56HDC2010 sensor(ADDRTHS);
57
58/* sensor side here */
59
60
61unsigned long startTime = 0;
62//unsigned long lastSMSTime = 0;
63
64bool ledState = 0;
65
66
67/*
68  Function to parse the server responce
69  Vars:
70    Type     ==> GETACTUATOR / POSTSENSOR
71    value    ==> int [send this value for SENSOR, update this for ACTUATOR]
72    timeout  ==> int, timeout in seconds to wait for and parse the server responce
73  Returns:
74    1 on success
75    0 on error [found closed socket or PDP deactivation]
76    -1 on server timeout
77*/
78int readServerResponse(int timeout){
79
80  unsigned long startTime;
81  int ret =0;
82  startTime = millis(); 
83  delay(10);
84  __itbpDebugPort__.println(F("start read..."));
85  while(true){
86    client.readline(1000);
87    __itbpDebugPort__.println(client.resp);//just to see the server response
88    if (strstr(client.resp, "1;"))
89    {
90        __itbpDebugPort__.println(F("found confirmation..."));
91        ret = 1;
92    }
93
94    if (strstr(client.resp, "0;"))
95    {
96        __itbpDebugPort__.println(F("error returned..."));
97        ret = -1;
98    }
99    
100    if (strstr(client.resp, sockDisconnected0)||strstr(client.resp, sockDisconnected1)||strstr(client.resp, sockDisconnected2))
101    {
102        __itbpDebugPort__.println(F("sk disconnected..."));
103        client.stop();  //4 LTE and 3G
104        return ret;
105    }//sockDisconnected0
106    
107    if(millis() - startTime > (unsigned long)timeout*1000 )
108    {
109       __itbpDebugPort__.println(F("mark to..."));
110        client.stop(); //need to clean DATA interface and return the to AT command interface 
111        return -2;        
112    }  
113 }
114  return -3;//never here
115}
116
117
118
119
120void sendGetRequest(char * sensorTocken, double sensorData){
121    String data;
122    //data = String(cloudURL) + String(sensorTocken) + String(sensorValURL) + String(humidity, DEC);
123    data = String(cloudURL) + String(sensorTocken) + String(sensorValURL) + String(sensorData);
124    __itbpDebugPort__.println(data);
125
126    client.print("GET ");
127    client.print(data);
128    client.println(" HTTP/1.1");
129    client.println(F("Host: " SERVER_ADDRESS));
130    client.println(F("Connection: close"));
131    client.println();
132}
133
134
135
136void sendData( void){
137    //send temperture data
138    if (client.connected() || client.connect()){
139
140      sendGetRequest(tempTocken, temperature);
141
142      readServerResponse(SERVER_REPLY_TIMEOUT);
143    }else{
144      __itbpDebugPort__.println(F("Socket/GPRS error...")); 
145    }
146    //send humidity data
147    if (client.connected() || client.connect()){
148      //client.print(demoData);
149      sendGetRequest(humiTocken, humidity);
150      //client.println("\r\n");
151      readServerResponse(SERVER_REPLY_TIMEOUT);
152    }else{
153      __itbpDebugPort__.println(F("Socket/GPRS error...")); 
154    }
155}
156
157
158void setup(){
159#if (__itbpModem__ == xyzmIoT)
160 delay(10000);
161
162  pinMode(ENABLEHALL, OUTPUT);
163  digitalWrite(ENABLEHALL, HIGH);   // power the HALL sensor
164
165#endif
166
167  __itbpDebugPort__.begin(115200);   //start debug port connection
168  //configure led
169 pinMode(13, OUTPUT);               //embedded LED status indicator  
170 digitalWrite(13, LOW);   
171  ledState = 0;
172
173 /*sensor side*/
174 sensor.begin();                  //I2C THS sensor init
175  sensor.reset();                     //reset H2010
176
177  //sensor.setTemperatureOffset(0b11000000);  //-10.32
178  sensor.setTemperatureOffset(0b11010111);    //-6.64
179
180
181  
182  // Set up the comfort zone
183  sensor.setHighTemp(28);         // High temperature of 28C
184  sensor.setLowTemp(22);          // Low temperature of 22C
185  sensor.setHighHumidity(55);     // High humidity of 55%
186  sensor.setLowHumidity(40);      // Low humidity of 40%
187
188  // Configure interrupt pin
189  /*sensor.enableInterrupt();                   // Enable the Interrupt/DRDY pin
190  sensor.enableThresholdInterrupt();          // Enable Interrupt triggering based on comfort zone
191  sensor.setInterruptPolarity(ACTIVE_HIGH);   // Set Interrupt pin to Active High
192  sensor.setInterruptMode(COMPARATOR_MODE);   // Set Interrupt to return to inactive state when in bounds
193  */
194    // Configure Measurements
195  sensor.setMeasurementMode(TEMP_AND_HUMID);  // Set measurements to temperature and humidity
196  //sensor.setRate(ONE_HZ);                     // Set measurement frequency to 1 Hz
197  sensor.setRate(MANUAL);                     // Set measurement frequency to 1 Hz
198  sensor.setTempRes(FOURTEEN_BIT);
199  sensor.setHumidRes(FOURTEEN_BIT);
200
201  /*
202  // Configure Measurements
203  //sensor.setRate(ONE_HZ);                     // Set measurement frequency to 1 Hz
204
205  // Configure THS Interrupt Pin
206  pinMode(ALERTTHSPIN, INPUT);                   // ALERTTHSPIN will be the interrupt input
207  attachInterrupt(digitalPinToInterrupt(ALERTTHSPIN), alertTHS, CHANGE);  //ISR "alertTHS" will be triggered by changes in ALERTTHSPIN
208  // Configure HALL Interrupt Pin
209  pinMode(ALERTHALLPIN, INPUT_PULLUP);                   // ALERTHALLPIN will be the interrupt input
210  attachInterrupt(digitalPinToInterrupt(ALERTHALLPIN), alertHALL, CHANGE);  //ISR "alertHALL" will be triggered by changes in ALERTHALLPIN
211
212  */
213  //begin measuring
214  sensor.triggerMeasurement();
215  temperature = (double)sensor.readTemp();
216  humidity = (double)sensor.readHumidity();
217 /*sensor side*/
218
219
220
221#if __itbpModem__ != xyzmIoT
222 DEBUGP(F("Free RAM: "), freeRam());
223#endif
224__itbpDebugPort__.println(F("...let's rock"));
225__itbpDebugPort__.flush();
226 
227 client.begin();
228
229 client.enableClockUpdate(1); //update available at next GSM boot
230
231 client.getIMEI(); //IMEI value in client.resp
232 memset(IMEI,0x00, sizeof(IMEI));
233 strcpy(IMEI,client.resp);
234 DEBUGP(F("IMEI: "), IMEI);
235
236 client.attachGPRS();
237 __itbpDebugPort__.println("connecting...");
238 
239 
240  startTime = millis() + (unsigned long)samplingPeriod*1000;//force send on the spot
241}
242
243
244
245
246void loop(){
247 if (millis() - startTime < (unsigned long)samplingPeriod*1000){//waiting period
248    //__itbpDebugPort__.println(F("..."));
249
250  ledState = ! ledState;
251  if(ledState != 0)
252    digitalWrite(13, HIGH); 
253  else
254    digitalWrite(13, LOW); 
255  delay(500);
256   
257 }
258 else{
259
260  startTime = millis();
261  digitalWrite(13, HIGH);   //show sampling + uploadto cloud
262
263  __itbpDebugPort__.println(F(""));
264  
265  
266  sensor.triggerMeasurement();
267    delay(500);
268    temperature = /*100**/(double)sensor.readTemp();
269    humidity = /*100**/(double)sensor.readHumidity();
270    DEBUGP(F("Temp: "),temperature);
271    DEBUGP(F("Hum%: "),humidity);
272    /*
273    alarmHALL = digitalRead(ALERTHALLPIN);
274    DEBUGP(F("Hall: "),alarmHALL);
275  
276  if (client.connected()) client.transparentescape();         //switch to AT mode - not really neaded, but just to be sure
277  
278  client.getVoltage(); //Vbat value in client.resp
279  VBAT = atof(client.resp);
280  DEBUGP(F("Voltage: "),VBAT);
281
282  client.getRTC(); //RTC value in client.resp
283  memset(dttime, 0x00, sizeof(dttime));
284  strcpy(dttime,client.resp);
285  DEBUGP(F("Time: "),dttime);
286  */
287  if (!client.connected()) client.transparent(); //switch to transparent socket mode, if available
288  
289  DEBUG(F("send sensors start"));
290  sendData();     //push sensors to the cloud
291  DEBUG(F("send sensors stop"));
292  
293    digitalWrite(13, LOW);     //show sampling + uploadto cloud
294  ledState = 0;
295 }
296
297}
298

e. Make some settings in some files contained inside "xyz-mIOT shield IoT Rest support" class
- in "itbpGPRSIPdefinition.h" line 2 set the APN value, using the APN value of your GSM provider (Eg: NET for RO Orange)
- in "itbpGPRSIPdefinition.h" line 9 set the SERVER_ADDRESS address for CLOUD Robofun
#define SERVER_ADDRESS "iot.robofun.ro"
#define SERVER_PORT "80"

- in "itbpGSMdefinition.h" comment default option for "__itbpModem__" and chose (delete comment sign) option
"#define __itbpModem__ xyzmIoT" (line 71)
- in "itbpGSMdefinition.h" chose the right modem for your xyz-mIoT flavour: for M95FA chose
"#define xyzmIoTmodem TWOG" (line 73)
or for BG96 chose
"#define xyzmIoTmodem CATM1" (line 75)

 

Step4 [Robofun cloud - define new sensors and copy TOKEN settings.]

Open https://iot.robofun.ro.

Create new account.
LTE CATM1 or GSM temperature and humidity IOT CLOUD monitoring using xyz-mIOT :: CREATE NEW CLOUD ACCOUNT

Add two new sensors (xyzmIOT_temperature and xyzmIOT_humidity).
LTE CATM1 or GSM temperature and humidity IOT CLOUD monitoring using xyz-mIOT :: create new sensor
Scroll down the page until "TOKEN" chapter.
LTE CATM1 or GSM temperature and humidity IOT CLOUD monitoring using xyz-mIOT :: copy cloud sensor token id


For each sensor, retain the "Tocken" id values. Those values will be used, next, to set sensors id[token id] in Arduino code.

In same page, a little bit above you will find the public Internet address where you will find the sensor data (observe marked in above picture).

 

Step5 [Arduino - sensors Tocken id, compile and upload IOT code]

Open in Arduino[(arduino.cc v >= 1.8.5] the xyz_mIoT_v41_temp_humidity.ino project.
LTE CATM1 or GSM temperature and humidity IOT CLOUD monitoring using xyz-mIOT :: ARDUINO SET SENSOR TOKEN a. Set tempTocken and humiTocken values with the one retained in previous step [created in the CLOUD].

If you use xyz-mIoT shield equipped with BG96 module you can select network registration mode as "GSM mode" or as "LTE CATM1 mode" (mobile network used and SIM card must support LTE CATM1*) by calling client.setNetworkMode(GSMONLY), respectively client.setNetworkMode(CATM1ONLY) function, right after client.begin() in function setup().
* we use for tests RO Orange LTE CATM1 enabled SIM.

b. Press twice (fast) the xyz-mIoT shield RESET button [the board will switch into programming mode]. LTE CATM1 or GSM temperature and humidity IOT CLOUD monitoring using xyz-mIOT :: ARDUINO SET xyz-mIoT board and port Select "itbrainpower.net xyz-mIoT" board and "itbrainpower.net xyz-mIoT" programming port in Arduino menu.

c. Compile and upload the code.

The xyz-mIoT shield will start to sample the temperature and humidity data (at 1min. rate) and to upload sampled values to the CLOUD.

LTE CATM1 or GSM temperature and humidity IOT CLOUD monitoring using xyz-mIOT :: debug messages In order to visualize the debug output use the Arduino Serial Monitor or other terminal by selecting the debug port with following settings: 115200bps, 8N, 1.

The temperature logged data can be visualized in Robofun cloud sensor page or, in public (shared) page as we specified in Step4 .
LTE CATM1 or GSM temperature and humidity IOT CLOUD monitoring using xyz-mIOT :: CLOUD SENSOR DATASET

 

ENJOY!

 

 

TUTORIAL PROVIDED WITHOUT ANY WARRANTY!!! USE IT AT YOUR OWN RISK!!!!

 

 

 

Dragos Iosub & itbrainpower.net team original how to.

 

 

 

 

document version 0.91 / 2018-05-21 © R&D Software Solutions srl