The environment monitoring system, based on the LoRa IoT interface, consists of a base station built using the Arduino Mega module with a LoRa gateway and remote stations based on the Arduino Feather, which connect to the base station via the LoRa radio interface.
The system allows monitoring of environmental parameters in the house and its immediate surroundings. All collected data is available via the Internet, and periodically sent SMS messages to a defined number. The system also has the ability to configure the alert system - in this situation, an alarm SMS is sent when one of the monitored parameters exceeds the set limits. All collected data is stored in the cloud, which allows you to analyze not only current parameters, but also historical data.
Apart from fire, every home or apartment owner is afraid of water the most. Regardless of whether it is a sudden failure - for example a broken pipe - or slowly leaking water from a leaking installation, this situation can lead to huge losses if it is not detected quickly enough. Failures of this kind can be problematic especially when we are away from home, which is why this system was created. One of the monitored parameters is humidity; its sudden jump allows you to detect a system failure in your home and either return faster or even notify your neighbors of the failure. The faster our reaction is, the smaller the losses.
Slow water leaks, caused by system leaks, are much more problematic. In addition to the fact that they are much more difficult to detect, they can damage the structure of the building or lead to the appearance of fungi on the walls. The system described here is also very helpful in identifying this type of situation. Thanks to the option of logging data over a long period of time, it is possible to determine periodic fluctuations in humidity in the rooms - a change in this behavior may indicate that a new water source has appeared somewhere in the building - for example, leakage from the installation.
Thanks to all these functions, it is possible to configure alarms in the system in such a way that as soon as there is a failure in the home, the system will inform us via SMS or e-mail about its occurrence - in the event of a sudden failure related to e.g. a pipe rupture with water, as well as case of deviations from normal humidity values in the apartment, which may indicate the appearance of small leaks. This makes it possible to monitor the situation at home, without having to use the Internet or regularly checking the Web page. If anything happens the system will inform us via SMS.
The LoRa IoT home monitoring system is based on ready-made, commercially available modules, which greatly simplifies its construction. Only a few connectors and switches have been added in-house. Elements for the construction of this system are available through Adafruit, Digikey or Sparkfun. These are standard modules used by hobbyists, so buying them will not be complicated.
To assemble the device, however, you will need soldering skills, especially SMD components, because you will need to solder dedicated radio connectors on the Feather board.
The whole system is programmed in the Arduino environment. Source codes are available on the project website, and a description of the program operation is provided below.
The aim of the project was:
* Creating a home IoT gateway based on the LoRa interface
* Creating a user interface for projects based on Arduino.
* Examine the applicability of the LoRa interface at home.
The developed LoRa gate is a minimalist device containing a minimal set of equipment and functions ensuring the operation of the environmental parameters monitoring system at home.
The intention to use the complete User Interface Framework is to make all configuration parameters available without having to change the code or recompile the program. Thanks to this changes will be introduced through a simple user interface on the system gate. Only four buttons and a 2x16 simple LCD display will be used to operate it. This display also shows the current environmental parameters - there are six modes of their presentation.
The credentials for external services (Temboo and Google Drive) are stored in a text file saved on the SD card.
The current version of the software on the base station and measuring stations meets the requirements described above. Exceptions to the solutions described above will be described in the text.
LoRa is a wireless communication interface with a long range, dedicated to use in Internet of Things systems. It was developed by Semtech, which implemented it in its integrated circuits, which are available, among others in Adafruit Feather modules. LoRa enables the implementation of simple, reliable and energy-saving wireless communication for telemetry systems, etc. It works perfectly in those systems where WiFi would be an excessive load. WiFi connections achieve very high speeds, but also consume a lot of energy to power the system. LoRa operates in the ISM band at 915 MHz, and WiFi in the range of 2.4 GHz to 5 GHz, which translates into lower data throughput, but at the same time increases the range and reliability of the system.
The LoRa IoT environmental parameter monitoring system, described below, consists of the following subsystems:
* LoRa IoT gateway - wireless hub for sensors and gateway to connect them to the Internet.
* Wireless indoor measuring station, equipped with a humidity sensor and a thermometer.
* Wireless outdoor measuring station equipped with humidity, pressure and temperature sensors.
The system gate periodically collects data from both stations - external and external, and performs a number of additional functions:
* Time synchronization with network time
* User interface support - 2x16 LCD buttons and.
* Handling alerts sent via SMS.
* Supports regular SMS prompts about temperature and humidity.
* Support for a website updated every 10 minutes.
* Supports cloud storage on Google Drive.
* Sleep and wake up measuring stations.
At the current stage of project development, communication in the described system is one-sided - the measuring stations only send data to the base station, which itself does not transmit any data to them. This is due to the fact that the LoRa interface provides - at leastat home - very reliable communication, so the implementation of two-way transmission protocol was not required.
The measuring stations send the measurement results to the base station about every 10 minutes (they do it asynchronously). These transmissions are very short and contain little data, so the chance for conflict - the arrival of messages from two measuring stations at the same time is minimal. In addition, a configurable protection has been built into the base station - if, after N ten-minute periods, no measurement comes from a given station (where N is configurable by the user), the system sends an SMS with information that it has lost contact with one of the measuring stations.
Information about the battery status (for an outdoor station with battery power) is also sent to the base station if the battery charge is too low. In addition, from the base station user interface, information is available on the strength of the radio signal from each base station, which allows you to determine how well the link works.
Step 1: LoRa gateway and base station
List of items needed for the base station:
1 x Adfaruit module with Arduino Mega 2560 R3
1 x Shield with Ethernet for Arduino with W5500 chip.
1 x I2C / SPI interface for LCD.
1 x Adafruit PID 1609 prototype board.
1 x Plate for LoRa RFM95W transceiver module.
1 x uFL SMT antenna connector.
1 x SMA adapter is uFL / u.FL / IPX / IPEX RF.
1 x 916 MHz antenna - half wave with SMA connector.
1 X LCD display 2X16 characters.
4 x SPDT button.
4 x Plastic button element.
2 x Grove - Universal 4 pin 20 cm cable.
1 x 9 V DC 650 mA plug-in power supply.
1 x microSD card with adapter. The capacity of 8 GB.
1 x Housing, QRP Labs
2 x Dedicated, custom-made panel (back, front).
1 x Ethernet cable.
In addition, we will need some pins, a cable, spacers and screws, nuts and washers to assemble everything together.
Ethernet Shield
Shield with the option of connecting to an Ethernet network is plugged into the module with Arduino Mega.
LCD
The LCD used a 2x16 character display, connected with the help of the Adafruit I2C / SPI module, which allows it to be connected to the Arduino Mega via I2C.
A set of pins (female) should be soldered to the LCD module, and analogically male to the I2C / SPI module. This will allow you to connect both elements together. I2C is derived through the Grove connector on the Ethernet module - in addition to the SDA and SCL lines there are +5 V and GND (ground). We prepare the appropriate cable, terminated with a Grove plug on one side, and soldered to the module connected to the LCD display on the other. We solder the cables as follows:
Arduino LCD
GND (black wire) GND
+ 5V (red wire) + 5V
SDA (white wire) DATE
SCL (yellow wire) CLK
RFM95W LoRa transceiver
More information about this module can be found a https://www.adafruit.com/products/3072" target="_blank" rel="noopener nofollow ugc" title="http:// https://www.adafruit.com/products/3072" class="postlink inline-block "> Adafruit website . Particularly important is accurate information on soldering the antenna connector in the uFL standard. To this connector on the transceiver board we attach an RF cable, which on the other side is terminated with a SMA panel socket. It will be mounted in the base station housing. We will later connect the LoRa antenna to the socket led out to the rear panel.
Communication between the RFM95W module and Arduino is made via SPI. The board with leads from RFM95W is mounted on the Adafruit Perma-Proto prototype board through a soldered pcb socket. They match the pins on the RFM95W module.
Then connect the output from the LoR transceiver to the Arduino, soldering the wires on the prototype board properly so that they can be connected to the appropriate pins of the Arduino module. Connections are made as follows:
Arduino RFM95W
GND GND
+5 V VIN
Digital pin 2 (interrupt 0) G0 (interrupt with RFMW9)
Digital pin 52 (SPI SCK) SCK
Digital pin 50 (SPI MISO) MISO
Digital pin 51 (SPI MOSI) MOSI
Digital pin 8 CS (Chip Select)
Digital pin 9 RST (Reset)
Buttons for controlling the base station
The LoRa IoT gateway has the following four buttons:
FUNC - Entry and exit to individual base station functions
ENTER - Accepts the set parameter
UP - Increment the parameter value
DOWN - Decrement the parameter value.
It's a good idea to use good-quality buttons here to keep them simple and legible to the user. The use of a cheap substitute will result in the difficulty of using the interface in the LoR gateway.
These buttons have three pins: common (c), normally open (no) and normally closed (nc). The common terminals of all buttons are connected to the ground of the Arduino module through a Grove cable, connected to the UART port on the board with the Ethernet module. Other wires in this cable have been cut off - only the weight will be used.
Terminals (no) are not connected, while terminals (nc) are connected to the buttons as follows:
Arduino Button
Digital pin 19 FUNC
Digital pin 18 ENTER
Digital pin 17 DOWN
Digital pin 16 UP
Now you can program Arduino with the code available on the project website. The user interface accessible from the gateway level is described below.
After loading the software (see below), the gate should be able to open without any problems.
Step 2: Internal measuring station
To set up a measuring station that works in a room you will need:
1 x Feather 32u4 RFM95 module - 868- or 915-MHz
1 x 12 and 16 pin female connectors
1 x FeatherWing prototype board
1 x Plate with SHT31-D humidity and temperature sensor
1 x 4 pin female connectors
1 x USB A - micro USB cable
1 x Power adapter with USB 5 V 1 A plug
In addition, you will need cables to make connections between the modules on the prototype board.
The Adafruit website has detailed instructions:
1. Pin soldering and Feather RFM95 antenna - https://learn.adafruit.com/adafruit-feather-32u4-radio-with-lora-radio-module/" target="_blank" rel="noopener nofollow ugc" title="http:// https://learn.adafruit.com/adafruit-feather-32u4-radio-with-lora-radio-module/" class="postlink inline-block "> link
2. Pin soldering to the SHT31-D module - https://learn.adafruit.com/adafruit-sht31-d-t...dity-sensor-breakout/wiring-and-test?view=all " target="_blank" rel="noopener nofollow ugc" title="http:// https://learn.adafruit.com/adafruit-sht31-d-t...dity-sensor-breakout/wiring-and-test?view=all " class="postlink inline-block "> link
3. Soldering pins to the FeatherWing prototype board - https://learn.adafruit.com/featherwing-proto-and-doubler" target="_blank" rel="noopener nofollow ugc" title="http:// https://learn.adafruit.com/featherwing-proto-and-doubler" class="postlink inline-block "> link
Solder the four-pin connector on the FeatherWing board as shown in the picture above, so that the VIN and GND pins of the radio module are connected to 3.3 V and GND, respectively, on the prototype board. Then with the help of a thin cable we have to make the following connections on this board:
FeatherWing SHT31-D
SDA SDA
SCL SCL
The SDA and SCL pins are marked on the prototype board in the upper right corner when it is placed as in the picture above. Then we can connect the prototype board to the Feather module.
After assembling the module, we can program the station with the program available on the project page, which is loaded via a USB cable. Then, after connecting the power supply, the system should start automatically and send measurement results to the LoRa IoT base station every 10 minutes.
Step 3: Outdoor measuring station
To assemble a measuring station that will work outside we need:
1 x Feather 32u4 RFM95 module
1 x FeatherWing Doubler prototype board
1 x uFL SMT antenna connector
1 x Adapter from SMA to uFL / u.FL / IPX / IPEX
1 x 916 MHz half-wave antenna with SMA plug
1 x Universal plate
1 x Small, plastic housing in waterproof version
1 x Lithium polymer battery with a capacity of 2000 mAh
1 x Charger with MPPT module for solar cells
1 x 2 pin JST cable
1 x Photovoltaic module with 2 W Sparkfun SKU PRT-13781
1 x Thermometer based on DS18B20 in waterproof version - Sparkfun SKU SEN-11050
1 x BME280 board for weather sensors
2 x Screw terminals with 3.5 mm pitch.
1 x Davis Instruments Solar Radiation Shield 7714 module, Amazon
1 x Piece of Lexan or Plexiglas
In addition, you will need some goldpins, cables, washers and screws with nuts and silicone to seal the housing,
The first part of the elements - the battery, inverterfor the PV module, the FeatherWing Doubler prototype board and the Feather 32u4 RFM95 LoRa Radio module are mounted in the plastic housing of the device.
Then mount the universal plate and BME280 sensor on the Davis Instruments Solar Radiation Shield module. Photovoltaic panels should be mounted on the top side of this module, as shown in the pictures above,
The author of the project tested various combinations of pressure, temperature and humidity sensors, BME280 proved to be the most reliable and gave measurements consistent with weather data for a given place. This sensor has an integrated thermometer, hygrometer and barometer. The system tests lasted several months, including winter. All this time BME280 did not cause any problems.
Housing and solar power supply
The assembly of the whole system begins with cutting the plexiglass to the dimensions of the smaller housing. Then we need to drill holes in it with the same spacing as in the housing, through which we screw it to the housing.
After mounting in the electronics housing, we can determine the location of the antenna socket in the module. We can drill a suitable hole in the housing, and next to it two more - one for connecting the BME280 module and the other for connecting the DS18B20 temperature sensor.
Then we need to drill further holes in the plexiglass for the Sunny Buddy module, which must be located so that its mounting holes match the holes on the FeatherWing Doubler prototype board, as in the photo above.
According to https://learn.sparkfun.com/tutorials/sunny-buddy-solar-charger-v13-hookup-guide-" target="_blank" rel="noopener nofollow ugc" title="http:// https://learn.sparkfun.com/tutorials/sunny-buddy-solar-charger-v13-hookup-guide-" class="postlink inline-block "> connection instructions solder on the converter module screw connectors in places marked "Solar In" and "Load". Then we can mount the inverter to the plexiglass using sufficiently long screws to enable assembly of the prototype board with suitably long distributors.
After assembling this part of the device in the housing, mount the SMA socket on the appropriate adapter and place the battery in the housing. The antenna cable will run next to the Sunny Buddy to the LoR transceiver.
We can now mount cut plexiglass in the housing together with the other modules.
We connect the battery to the JST connector marked "BATT" on the solar converter module. The cables from the solar module are connected to the pre-soldered screw connector on the converter module, remembering about the correct polarity of the input. Connect the cable with the JST-2 connector to the "Load" connector on the Sunny Buddy, remembering that the red cable goes to the plus and the black to the minus in the socket.
At this stage, the module is ready to mount the prototype board and LoR transceiver.
Installation of the radio transceiver and prototype board
The uFL socket for the antenna is soldered to the 32u4 RFM95 module https://learn.adafruit.com/adafruit-feather-32u4-radio-with-lora-radio-module/antenna-options" target="_blank" rel="noopener nofollow ugc" title="http:// https://learn.adafruit.com/adafruit-feather-32u4-radio-with-lora-radio-module/antenna-options" class="postlink inline-block "> according to the instructions .
The female sockets that are delivered with the FeatherWing Doubler prototype board are assembled on one half of the board, as shown in the picture above. The other half will remain unused. Then solder the connectors on the board,as shown in the picture, to connect the power supply (3.3 V and GND) and I2C signals - SDA and SCL - to the socket for the BME280 module.
Next, solder on the prototype board another connector, dedicated for DS18B20. Connect the power supply (3.3 V and GND) and the output from digital pin number 5 (this will be our 1-Wire interface) to the connector for this sensor. Pass the sensor cable through the previously prepared hole in the housing and solder the connector to it, which we plug into the socket prepared on the prototype board.
Finally, we can gently plug the adapter into the antenna socket, the other side of which is screwed into the housing to be able to attach the external antenna.
The assembly of this module is completed by plugging the prototype board into the Sunny Buddy module and assembling it necessarily using spacers, so that the components of both modules do not touch each other.
Now we can upload the software to the board. Once done, we can connect the Feather module to the prototype board. Do not connect the cable with JST connector from the "Load" output of the Sunny Buddy module at this stage. Later we will connect this cable to the port where the battery is normally connected to the Feather module.
After assembly, seal the cable openings in the housing with silicone. Thanks to this, the housing will be tight.
Shield Solar Radiation
Let's follow http://www.davisnet.com/product_documents/weather/manuals/07395-093_IM_07714.pdf" target="_blank" rel="noopener nofollow ugc" title="http:// http://www.davisnet.com/product_documents/weather/manuals/07395-093_IM_07714.pdf" class="postlink inline-block "> assembly instructions for this module . Then install this module as shown in the photo above. On https://learn.adafruit.com/adafruit-bme280-hu...pressure-temperature-sensor-breakout/assembly" target="_blank" rel="noopener nofollow ugc" title="http:// https://learn.adafruit.com/adafruit-bme280-hu...pressure-temperature-sensor-breakout/assembly" class="postlink inline-block "> Adafruit website we will find instructions for connecting this module with BME280. Then solder the protector to the prototype board.
Using the pictures shown above, combine together both modules using a prototype board. Using the cable pieces, connect the outputs from BME280 (VIN, GND, SCK and SDI) to the socket on the prototype board that we just soldered. Then we attach the pins from the FeatherWing Doubler module to it as follows:
3.3 V - VIN
GND - GND
SDA - SDI
SCL - SCK
The mounting holes on the Adafruit prototype board have the same spacing as the shield dedicated to monitoring sunlight. Thanks to this, it is possible to easily connect everything with a few screws.
In the picture above one more row of female pins is visible. They were used during initial experiments with the system, aimed at selecting the best sensor - they are not needed for normal operation of the system.
Then we cut a piece of plexiglass, as shown in the photo - the cut fragment should be the width of the solar panel, but long enough for it to be screwed together with the panel to the appropriate shield. After installing the module prepared in this way, it will be slightly inclined, thanks to which it will be better to collect sunlight during the day.
In the plexiglass, we drill holes for mounting the photovoltaic panel and a dedicated shield for it, and we turn everything together, as in the photo above.
At this stage, we can connect the rest of the system to the "Load" connector to the Sunny Buddy module. The cable with JST connector is connected to the battery input of the Feather module. The weather station should immediately turn on and start broadcasting - every 10 minutes it should send a report with the measured parameters to the LoRa gateway in our system. The assembled measuring station has been working for the author of the project since October 2016 - it survived the winter without fail.
Step 4: LoRa IoT base station user interface
The menu displayed on the LCD screen of the base station presents a simple user interface controlled by four buttons we installed earlier in it. This menu allows you to easily add or remove functions from the system.
The interface is operated by four buttons: Func, Enter, Up and Down. The exact operation of the user interface is contained in the documentation in PDF files for download on the project website.
The interface has a number of options:
1. Turning the LCD backlight off and on.
Turns off the LCD backlight. After turning it off, just press the Func key to turn the backlight on again.
2. Display mode configuration.
Configures how the data is displayed in the second line of the display. There are three operating modes, each of which can be configured to display temperature or humidity, which together gives six options for data presentation.
The screen can display the latest data from the station that last sent the report, data from only one station or alternately from both.
3. RSSI display
RSSI is a signal strength indicator. It allows you to display the strength of the signal received by the LoRa transceiver from each station. After the station list, scroll with the Up and Down keys.
4. Battery status display
Displays battery voltage - the supply voltage of each of the 32u4 RFM95 transmitters in our LoRa network. On the station list, scroll with the Up and Down keys.
5. Setting alarms.
This function allows you to enable and disable alarms and configure their level. In the current version of the software, alarms related to high humidity, low battery and loss of contact with the station are available.
6. Setting humidity alarm level.
This function allows you to configure the humidity level for each station separately.
7. Setting the number of measuring stations.
By default, the system starts with one active station. A maximum of ten independent measuring stations can be connected to the gate. The number of stations must be configured before we can start using the next option - the function of giving stations unique names.
8. Setting station names.
Allows editing station names. The name can have up to nine characters.
9. Time setting - winter / summer.
It allows you to set whether the change from winter to summer time and vice versa is enabled or not.
10. Time zone setting.
It allows you to configure our time zone. Identified by the main city located in the given zone.
11. Setting the pressure sensor calibration offset.
It allows you to configure a constant pressure offset related to the height of the measuring station. Let's configure it so that the pressure values are the same as in the data available on meteorological portals in our area.
12. Choice of temperature units.
It allows you to choose in which units the temperature is given: degrees Celsius or Fahrenheit.
Step 5: Notifications and alerts via SMS
The pictures above show notifications and alerts sent with the help of text messages (SMS).
Notifications are sent via SMS about every hour. The LoRa base station is configured to send SMS to the indicated number half an hour after every equal hour. 160 characters can fit data from four measuring stations (temperature and pressure).
The content of the notification depends on the content of the sendStatus () function in the Temboo module software in the base station program code.
The alarm is sent via SMS when the selected parameter exceeds the programmed threshold. Alarm levels are set for each station separately. The SMS format is defined by the sendAlert () function in the gateway software.
SMS messages are sent via the email gateway to the operator's SMS. For the major US mobile operators, the email address is configured as follows:
AT&T: [10 digit phone number] @ txt.att.net
Sprint: [10 digit phone number] @ messaging.sprintpcs.com
T-Mobile: [10 digit phone number] @ tmomail.net
Verizon: [10 digit phone number] @ vtext.com
Sending an email to the provided address will cause the user of the given 10-digit telephone number to receive an SMS. Email addresses for our operator can be found on the Internet. The phone number is stored on the SD card in the system.
To send emails from the gateway, an Temboo account and Gmail address are required. On the Google website, we configure email and Google Drive, also used by the system (see below). Then on the Temboo website we set up the account - for 30 days the account is free, then we have to pay a small fee.
On Temboo, we configure Google Gmail SendEmail Choreo, which allows you to send email via Gmail. The credentials for logging into the Temboo service are saved to a file on the SD card.
Step 6: Storing data in the cloud
The image above shows how the data collected by individual measurement modules are collected in a spreadsheet on Google Drive. Data is sent from the base station to Google Drive every hour, about two minutes after each full hour.
The first column shows the time when the entry was sent. If it is midnight, the time is replaced by the date. The content of further columns in Google Sheet is defined by the content of the spreadsheetUpdate () function in the program related to the Temboo functions. If we want to save data from a larger number of measuring stations or modify the format of stored data in any way, it is in this piece of code.
You need a Temboo account to transfer data to Google Drive from our LoRa IoT base station. As described above, we first set up a Google account, then set up a Temboo account and configure it. We will obtain account verification data by creating a Google spreadsheet under the name AppendValuesChoreo. We'll find more information about authentication later in the text.
Step 7: Web application panel
The image above shows the AdafruitIO panel, showing in real time the status of our installation and the results of measurements. The data presented on the web is updated every three minutes.
The AdQruit MQTT queuing system client is included in the software for the LoRa IoT gateway. This client publishes data streams through AdafruitIO, which acts as a queued information broker. Each data stream - feed - is responsible for one parameter from one device, for example temperature from an external sensor. Adafruit provides the right tools to create a Web page that displays this data in a configurable way.
Adafruit has published very good tuto rial describing the creation of an Adafruit account and the configuration of data streams and their display on AdafruitIO. The system is currently in beta testing and limits the number of data streams to ten.
In the LoR gateway program of our system, the login details - username and password - are stored in the AIO_Account.h file:
After changing this data, you must re-compile the gateway program and load it into the system.
In subsequent versions of the software for LoR IoT deficiencies, the author plans to store the above data together with login data for Google and Temboo services on an SD card, so that no recompilation of sources will be needed.
Currently AdafruitIO does not work perfectly stable - the connection breaks after about 24..48 hours of work and it is not possible to reset from the device. But, as described above, this system is only in the beta stage. This does not affect the operation of other LoR gateway functions.
The author plans to incorporate the Web server into the device in future versions of the software, thanks to which the website will be presented without the need to use the MQTT queuing system and connection with AdafruitIO. Implementation of this task - creating an HTML5 page with JavaScript - should be within the reach of Arduino Mega.
Step 8: LoRa IoT gateway software
The source code for the gate is available on the project website. It is written in a rather procedural style and has a lot of comments, which should make it easier to edit and understand. The repository with all soft can also be downloaded from github .
In the current version, the only user change required is the addition of login credentials to the AIO_Account.h file, as described above. All other options are configured in the system through the gateway user interface, and the authentication data for logging into Google and Temboo is contained on the SD card.
Below you will find a general description of the source code and what it contains.
Setup
The code contained in this part initializes the individual Arduino pins for communication with the systems in the gate, initializes the SD card, LCD and initiates the sequence of initialization of individual peripherals in the system.
eepromRead ()
The first time the gate is started, the system saves to the EEPROM the default settings, each time it is started it is read from that memory. They can be changed from the user interface. A message on the LCD will indicate whether the data has been read from the Arduino or the default has been uploaded.
RFM95Initialize ()
This procedure performs a hard reset of the LoR transceiver and then initializes it by configuring to work with 915 MHz with +23 dBm transmission power (although Tx is not currently used by the gateway). In future versions of the software, the transmission frequency and transceiver power will be set through the gate's user interface.
ethernetInitialize ()
Procedure initiating connection to the network via Ethernet. The system will work as a DHCP client, so the router should give IP to the gateway, which will display it on the LCD.
readGatewayData ()
Reads login data for Temboo and Google services from the SD card.
sendStatus ()
It sends an SMS with a notification containing empty data fields - allows you to check whether authentication in the Temboo and Gmail services is working.
spreadsheetUpdate ()
Updates the content of the Google spreadsheet in the Drive service with all zeros, which allows you to verify that the authentication in the Temboo and Google Drive services works correctly
AIOconnect ()
Connects to the AdafruitIO MQTT broker, which allows you to verify that the authentication in this service works correctly.
Main program loop
The main program loop - loop () - performs the following actions sequentially:
First, it is checked if the Func button has been pressed, if so, Function () is performed, which performs procedures related to the user interface on the gate's LCD. The program then launches the systemTimeUpdate () function, which updates the system time; if at least a second has passed since the previous iteration of the program loop (i.e. the second counter increased), the program performs the following operations:
Checks whether the number of seconds is equal to the configured time at which the defined operations are performed every minute. For now, two such operations are defined - in zero seconds of every minuteAdafruit MQTT data broker ping system, and in 50 seconds every minute updates the second line of the display, as recorded in its configuration.
The next steps are procedures that are repeated over a long period of time:
Every 10 minutes, the system publishes data in the AdafruitIO stream and checks whether there is a need to send a predefined alarm SMS.
Every hour, two minutes after the full hour, a data update is sent to Google Drive. Three minutes after a full hour, the system updates its time using the Network Timing Protocol (NTP). Four minutes after a full hour, the system checks the connection to Adafruit MQTT - if it does not work, it tries to reconnect to this service.
Half an hour after the full hour, SMSes are sent with notifications that contain information on measurements, etc. 40 minutes after the full hour, the system re initializes the LoRa radio system. It is required by the fact that during such a long work LoR transceivers can hang up etc, and re-initializing them every hour, at a constant and controlled time, causes that this type of problem does not occur.
After performing cyclical operations, the system checks whether the LoRa transceiver has received any data packages from the measuring stations, if so, it begins processing them and updates the data displayed on the LCD screen in the second line in the latest measurement presentation mode.
Interrupt support
The LoRa gateway uses one interrupt, which is related to pressing the Func button in the user interface. Thanks to emu, when the menu control button is pressed, the system will terminate the currently implemented function and perform functions related to the operation of the user interface. The interrupt has been configured so that it will be disabled when the user interface function starts.
After returning from interruption, the system starts NTP, which allows you to update the system time to the current time,
RFM95W radio network functions
getRadioPacket ()
The procedure is started when the LoRa radio in the core network receives a data packet from an external station. This procedure appends the signal strength and arrival time of the data packet to the appropriate matrix, and of course reads it.
checkAlerts ()
The procedure runs in the main program loop every ten minutes. If any of the defined situations occur - loss of connection to a remote station, high humidity level or low battery level, this procedure will start sending an alarm SMS.
Temboo procedures
sendStatus ()
Procedure that generates a message to be sent via email gateway to an SMS. By default, the software is configured to send humidity and temperature data in the first four measuring stations in an SMS. If we want to change the content of the SMS notification, this is the procedure we are looking for.
sendAlert ()
A procedure similar to the one above that generates an e-mail to be an SMS alarm. It is activated when a defined alarm situation occurs. The content of this procedure should be changed if we want to change the content of emergency messages.
sendEmail ()
A procedure, generated by Temboo, for sending emails via Temboo Gmail Choreo.
spreadsheetUpdate ()
Updates the data compacted in the Google spreadsheet - an update is sent via Temboo Append Row Choreo, which adds one row to the spreadsheet on Google Drive. The content of this function should be modified if we want to change the way of sending data to Google spreadsheet or its format.
sendSpreadsheetUpdate ()
Code, generated by Temboo, for sending data to Google Drive via Temboo.
Functions dedicated to timing
systemTimeUpdate ()
Counts the seconds of local time. This function also updates the time displayed on the LCD (in HH: MM: SS 24h format).
ntpTimeUpdate ()
This function, called every hour from the main program loop, locates with the time of the local network gateway - uses the getNTPtime () function to get the current time, locates it taking into account the time zone and summer / winter time, and then displays on the gate screen, after correctly obtaining the time after NTP.
EEPROM functions
Functions related to EEPROM memory support are responsible for initialization, saving and reading data from this memory. Data in the EEPROM memory are saved in the form of the structure shown below. The readBlock () and updateBlock () functions from EEPROMex.h are responsible for reading and writing data in the form of such a structure to EEPROM, respectively.
To extend the life of the EEPROM memory (which has generally quite a limited number of write and read cycles), the data saving function - updateBlock () checks before saving if it will make any changes to the memory; if not, it does not physically overwrite the data.
The use of the data structure to store data in memory has a great advantage - in the future it allows easy modification, if anyone wants to add additional data to memory. The structure at the current stage of LoRa gateway software development is as follows:
Functions related to the operation of the LCD display and menu closing buttons
An enumerator (defined below) is used to index items in the LCD interface menu. By using the enumerator, there is no need to watch the numbering of individual options in the menu when adding more items. The enumerator starts with the entry "START_FUNCTIONS" and ends with "END_FUNCTIONS." Thanks to this - regardless of the number of options between these elements in the enumerator, the program always knows when it hits the beginning or end of the menu. The enumerator is defined as follows:
Every time you press the Func button, the program goes into a while (1) loop. Being in this loop, the program monitors pressing all four buttons. Their functions are:
FUNC - Causes you to exit Function () and return to the main program loop.
ENTER - Executes the currently displayed option in the menu.
UP - Scrolls the displayed option one step up.
DOWN - Scrolls the displayed option one step down.
After entering Function (), each time you press the Up or Down button, functionDisplay () will be performed, which changes the menu function currently displayed on the LCD. Similarly, after pressing Enter, functionExecute () will execute, which executes the given function from the menu.
Thanks to the presence of the data structure, adding new entries to the menu is very simple. Similar structures are used, for example, to describe the LCD operating mode during normal operation of the LoRa gate. A more detailed description of the data display modes is provided in the part of the article describing the user interface. The data structure describing the LCD display modes is as follows:
[Syntax=c]enum {
START_DISPLAY_MODES,
LAST_STATION_TEMP,
LAST_STATION_HUMI,
FIXED_STATION_TEMP,
FIXED_STATION_HUMI,
CYCLE_STATION_TEMP,
CYCLE_STATION_HUMI,
END_DISPLAY_MODES
};[/syntax]
The display also has a data matrix for display that the enumerator indexes:
[Syntax=c]const char* DISPLAY_MODE[] = {
" ",
"Last Stn Temp",
"Last Stn Humi",
"Fixed Stn Temp",
"Fixed Stn Humi",
"Cycle Stn Temp",
"Cycle Stn Humi",
" "
};[/syntax]
This technique was not used in more places in the program, although it could, because it allows to save the system's RAM. A more detailed description of the use of such structures in the program can be found here .
SD card operating procedures
Procedures related to the support of the SD card allow you to write and read data from this card in the LoRa gate, The readGatewayData () function reads from the SD card previously stored data for authentication in the Temboo and Google services. These data are saved in the GW_Data.txt file. More about the structure of this file below.
GW_Data.txt files contain text limited by square brackets, so we assume that there are no such brackets in the password, etc. If you need to use other characters to restrict the texts in this file. This function reads data into the gatewayData string matrix [12]. Individual elements of the matrix are described by names from the following enumerator.
Thanks to this type of structure, further entries can be added to these data if needed.
LCD operating procedures
The updateStationDisplay () function is responsible for generating the lastStationDisplay string, which contains data to be displayed in the second LCD line. This string is generated according to the display mode settings. Each time any function updates the data status, the lastStationDisplay () function is used to update the content of the string to be displayed on the LCD.
To simplify LCD operation, a number of functions are used for simplicity:
* updateDisplayLine12 (String Line_1, String Line_2) - updates lines 1 & 2
* updateDisplayLine1 (String Line_1) - updates line 1 leaves line 2 intact
* updateDisplayLine2 (String Line_2) - updates line 2 leaves line 1 intact
* clearDisplayLine1 (String Line_1) - clears lines 1 & 2 and updates line 1
* clearDisplayLine2 (String Line_2) - clears lines 1 & 2 and updates line 2
Step 9: Software for the internal measuring station
LoRa network measuring stations - internal and external - are generally called remote stations. Each remote station has its unique ID number, so it can be correctly identified by the LoRa gateway. The identification number is rigidly stored in the software of each remote station. If we want to change this unique identification number, we must recompile the software for the given station again.
In the current version of the software the number of identification numbers in the system is rigidly limited. The ID can be from 0x00 to 0x09, which gives 10 stations. In future versions, the station numbering is to be done automatically by the gate after connecting to the station. Thanks to this, it will be possible to add more stations to the system in a completely seamless way.
The libraries provided by Adafruit are used to initialize and read data from the SHT31 sensor. In addition to the data read from this sensor, the station also sends other data to the LoR gate. They are sent in the form of the data structure shown below:
The above data union allows you to map floating point values to bytes, so you can transfer them via the wireless interface. Similarly, other types of variables, such as thongs, can be sent. The number of sent variables can be increased - just add them to the structure described in more detail below.
The indoor weather station sends information about the air temperature (airTemp) and supply voltage (bat volt) to the base station. In the case of an indoor station, the supply voltage is taken from the supply voltage to the Feather module. Other data, such as ground temperature (gndTemp) or pressure (pressure) are set to zero.
The size of packets sent via the wireless network is 5 float variables (5 bytes each) plus one byte for the station ID number - 21 bytes in total. The LoRa network packet is built through the buildWirelesspacket () function, which uses binary variable mapping as follows:
[syntax=c]for(int n=0; n
The system allows monitoring of environmental parameters in the house and its immediate surroundings. All collected data is available via the Internet, and periodically sent SMS messages to a defined number. The system also has the ability to configure the alert system - in this situation, an alarm SMS is sent when one of the monitored parameters exceeds the set limits. All collected data is stored in the cloud, which allows you to analyze not only current parameters, but also historical data.
Apart from fire, every home or apartment owner is afraid of water the most. Regardless of whether it is a sudden failure - for example a broken pipe - or slowly leaking water from a leaking installation, this situation can lead to huge losses if it is not detected quickly enough. Failures of this kind can be problematic especially when we are away from home, which is why this system was created. One of the monitored parameters is humidity; its sudden jump allows you to detect a system failure in your home and either return faster or even notify your neighbors of the failure. The faster our reaction is, the smaller the losses.
Slow water leaks, caused by system leaks, are much more problematic. In addition to the fact that they are much more difficult to detect, they can damage the structure of the building or lead to the appearance of fungi on the walls. The system described here is also very helpful in identifying this type of situation. Thanks to the option of logging data over a long period of time, it is possible to determine periodic fluctuations in humidity in the rooms - a change in this behavior may indicate that a new water source has appeared somewhere in the building - for example, leakage from the installation.
Thanks to all these functions, it is possible to configure alarms in the system in such a way that as soon as there is a failure in the home, the system will inform us via SMS or e-mail about its occurrence - in the event of a sudden failure related to e.g. a pipe rupture with water, as well as case of deviations from normal humidity values in the apartment, which may indicate the appearance of small leaks. This makes it possible to monitor the situation at home, without having to use the Internet or regularly checking the Web page. If anything happens the system will inform us via SMS.
The LoRa IoT home monitoring system is based on ready-made, commercially available modules, which greatly simplifies its construction. Only a few connectors and switches have been added in-house. Elements for the construction of this system are available through Adafruit, Digikey or Sparkfun. These are standard modules used by hobbyists, so buying them will not be complicated.
To assemble the device, however, you will need soldering skills, especially SMD components, because you will need to solder dedicated radio connectors on the Feather board.
The whole system is programmed in the Arduino environment. Source codes are available on the project website, and a description of the program operation is provided below.
The aim of the project was:
* Creating a home IoT gateway based on the LoRa interface
* Creating a user interface for projects based on Arduino.
* Examine the applicability of the LoRa interface at home.
The developed LoRa gate is a minimalist device containing a minimal set of equipment and functions ensuring the operation of the environmental parameters monitoring system at home.
The intention to use the complete User Interface Framework is to make all configuration parameters available without having to change the code or recompile the program. Thanks to this changes will be introduced through a simple user interface on the system gate. Only four buttons and a 2x16 simple LCD display will be used to operate it. This display also shows the current environmental parameters - there are six modes of their presentation.
The credentials for external services (Temboo and Google Drive) are stored in a text file saved on the SD card.
The current version of the software on the base station and measuring stations meets the requirements described above. Exceptions to the solutions described above will be described in the text.
LoRa is a wireless communication interface with a long range, dedicated to use in Internet of Things systems. It was developed by Semtech, which implemented it in its integrated circuits, which are available, among others in Adafruit Feather modules. LoRa enables the implementation of simple, reliable and energy-saving wireless communication for telemetry systems, etc. It works perfectly in those systems where WiFi would be an excessive load. WiFi connections achieve very high speeds, but also consume a lot of energy to power the system. LoRa operates in the ISM band at 915 MHz, and WiFi in the range of 2.4 GHz to 5 GHz, which translates into lower data throughput, but at the same time increases the range and reliability of the system.
The LoRa IoT environmental parameter monitoring system, described below, consists of the following subsystems:
* LoRa IoT gateway - wireless hub for sensors and gateway to connect them to the Internet.
* Wireless indoor measuring station, equipped with a humidity sensor and a thermometer.
* Wireless outdoor measuring station equipped with humidity, pressure and temperature sensors.
The system gate periodically collects data from both stations - external and external, and performs a number of additional functions:
* Time synchronization with network time
* User interface support - 2x16 LCD buttons and.
* Handling alerts sent via SMS.
* Supports regular SMS prompts about temperature and humidity.
* Support for a website updated every 10 minutes.
* Supports cloud storage on Google Drive.
* Sleep and wake up measuring stations.
At the current stage of project development, communication in the described system is one-sided - the measuring stations only send data to the base station, which itself does not transmit any data to them. This is due to the fact that the LoRa interface provides - at leastat home - very reliable communication, so the implementation of two-way transmission protocol was not required.
The measuring stations send the measurement results to the base station about every 10 minutes (they do it asynchronously). These transmissions are very short and contain little data, so the chance for conflict - the arrival of messages from two measuring stations at the same time is minimal. In addition, a configurable protection has been built into the base station - if, after N ten-minute periods, no measurement comes from a given station (where N is configurable by the user), the system sends an SMS with information that it has lost contact with one of the measuring stations.
Information about the battery status (for an outdoor station with battery power) is also sent to the base station if the battery charge is too low. In addition, from the base station user interface, information is available on the strength of the radio signal from each base station, which allows you to determine how well the link works.
Step 1: LoRa gateway and base station
List of items needed for the base station:
1 x Adfaruit module with Arduino Mega 2560 R3
1 x Shield with Ethernet for Arduino with W5500 chip.
1 x I2C / SPI interface for LCD.
1 x Adafruit PID 1609 prototype board.
1 x Plate for LoRa RFM95W transceiver module.
1 x uFL SMT antenna connector.
1 x SMA adapter is uFL / u.FL / IPX / IPEX RF.
1 x 916 MHz antenna - half wave with SMA connector.
1 X LCD display 2X16 characters.
4 x SPDT button.
4 x Plastic button element.
2 x Grove - Universal 4 pin 20 cm cable.
1 x 9 V DC 650 mA plug-in power supply.
1 x microSD card with adapter. The capacity of 8 GB.
1 x Housing, QRP Labs
2 x Dedicated, custom-made panel (back, front).
1 x Ethernet cable.
In addition, we will need some pins, a cable, spacers and screws, nuts and washers to assemble everything together.
Ethernet Shield
Shield with the option of connecting to an Ethernet network is plugged into the module with Arduino Mega.
LCD
The LCD used a 2x16 character display, connected with the help of the Adafruit I2C / SPI module, which allows it to be connected to the Arduino Mega via I2C.
A set of pins (female) should be soldered to the LCD module, and analogically male to the I2C / SPI module. This will allow you to connect both elements together. I2C is derived through the Grove connector on the Ethernet module - in addition to the SDA and SCL lines there are +5 V and GND (ground). We prepare the appropriate cable, terminated with a Grove plug on one side, and soldered to the module connected to the LCD display on the other. We solder the cables as follows:
Arduino LCD
GND (black wire) GND
+ 5V (red wire) + 5V
SDA (white wire) DATE
SCL (yellow wire) CLK
RFM95W LoRa transceiver
More information about this module can be found a https://www.adafruit.com/products/3072" target="_blank" rel="noopener nofollow ugc" title="http:// https://www.adafruit.com/products/3072" class="postlink inline-block "> Adafruit website . Particularly important is accurate information on soldering the antenna connector in the uFL standard. To this connector on the transceiver board we attach an RF cable, which on the other side is terminated with a SMA panel socket. It will be mounted in the base station housing. We will later connect the LoRa antenna to the socket led out to the rear panel.
Communication between the RFM95W module and Arduino is made via SPI. The board with leads from RFM95W is mounted on the Adafruit Perma-Proto prototype board through a soldered pcb socket. They match the pins on the RFM95W module.
Then connect the output from the LoR transceiver to the Arduino, soldering the wires on the prototype board properly so that they can be connected to the appropriate pins of the Arduino module. Connections are made as follows:
Arduino RFM95W
GND GND
+5 V VIN
Digital pin 2 (interrupt 0) G0 (interrupt with RFMW9)
Digital pin 52 (SPI SCK) SCK
Digital pin 50 (SPI MISO) MISO
Digital pin 51 (SPI MOSI) MOSI
Digital pin 8 CS (Chip Select)
Digital pin 9 RST (Reset)
Buttons for controlling the base station
The LoRa IoT gateway has the following four buttons:
FUNC - Entry and exit to individual base station functions
ENTER - Accepts the set parameter
UP - Increment the parameter value
DOWN - Decrement the parameter value.
It's a good idea to use good-quality buttons here to keep them simple and legible to the user. The use of a cheap substitute will result in the difficulty of using the interface in the LoR gateway.
These buttons have three pins: common (c), normally open (no) and normally closed (nc). The common terminals of all buttons are connected to the ground of the Arduino module through a Grove cable, connected to the UART port on the board with the Ethernet module. Other wires in this cable have been cut off - only the weight will be used.
Terminals (no) are not connected, while terminals (nc) are connected to the buttons as follows:
Arduino Button
Digital pin 19 FUNC
Digital pin 18 ENTER
Digital pin 17 DOWN
Digital pin 16 UP
Now you can program Arduino with the code available on the project website. The user interface accessible from the gateway level is described below.
After loading the software (see below), the gate should be able to open without any problems.
Step 2: Internal measuring station
To set up a measuring station that works in a room you will need:
1 x Feather 32u4 RFM95 module - 868- or 915-MHz
1 x 12 and 16 pin female connectors
1 x FeatherWing prototype board
1 x Plate with SHT31-D humidity and temperature sensor
1 x 4 pin female connectors
1 x USB A - micro USB cable
1 x Power adapter with USB 5 V 1 A plug
In addition, you will need cables to make connections between the modules on the prototype board.
The Adafruit website has detailed instructions:
1. Pin soldering and Feather RFM95 antenna - https://learn.adafruit.com/adafruit-feather-32u4-radio-with-lora-radio-module/" target="_blank" rel="noopener nofollow ugc" title="http:// https://learn.adafruit.com/adafruit-feather-32u4-radio-with-lora-radio-module/" class="postlink inline-block "> link
2. Pin soldering to the SHT31-D module - https://learn.adafruit.com/adafruit-sht31-d-t...dity-sensor-breakout/wiring-and-test?view=all " target="_blank" rel="noopener nofollow ugc" title="http:// https://learn.adafruit.com/adafruit-sht31-d-t...dity-sensor-breakout/wiring-and-test?view=all " class="postlink inline-block "> link
3. Soldering pins to the FeatherWing prototype board - https://learn.adafruit.com/featherwing-proto-and-doubler" target="_blank" rel="noopener nofollow ugc" title="http:// https://learn.adafruit.com/featherwing-proto-and-doubler" class="postlink inline-block "> link
Solder the four-pin connector on the FeatherWing board as shown in the picture above, so that the VIN and GND pins of the radio module are connected to 3.3 V and GND, respectively, on the prototype board. Then with the help of a thin cable we have to make the following connections on this board:
FeatherWing SHT31-D
SDA SDA
SCL SCL
The SDA and SCL pins are marked on the prototype board in the upper right corner when it is placed as in the picture above. Then we can connect the prototype board to the Feather module.
After assembling the module, we can program the station with the program available on the project page, which is loaded via a USB cable. Then, after connecting the power supply, the system should start automatically and send measurement results to the LoRa IoT base station every 10 minutes.
Step 3: Outdoor measuring station
To assemble a measuring station that will work outside we need:
1 x Feather 32u4 RFM95 module
1 x FeatherWing Doubler prototype board
1 x uFL SMT antenna connector
1 x Adapter from SMA to uFL / u.FL / IPX / IPEX
1 x 916 MHz half-wave antenna with SMA plug
1 x Universal plate
1 x Small, plastic housing in waterproof version
1 x Lithium polymer battery with a capacity of 2000 mAh
1 x Charger with MPPT module for solar cells
1 x 2 pin JST cable
1 x Photovoltaic module with 2 W Sparkfun SKU PRT-13781
1 x Thermometer based on DS18B20 in waterproof version - Sparkfun SKU SEN-11050
1 x BME280 board for weather sensors
2 x Screw terminals with 3.5 mm pitch.
1 x Davis Instruments Solar Radiation Shield 7714 module, Amazon
1 x Piece of Lexan or Plexiglas
In addition, you will need some goldpins, cables, washers and screws with nuts and silicone to seal the housing,
The first part of the elements - the battery, inverterfor the PV module, the FeatherWing Doubler prototype board and the Feather 32u4 RFM95 LoRa Radio module are mounted in the plastic housing of the device.
Then mount the universal plate and BME280 sensor on the Davis Instruments Solar Radiation Shield module. Photovoltaic panels should be mounted on the top side of this module, as shown in the pictures above,
The author of the project tested various combinations of pressure, temperature and humidity sensors, BME280 proved to be the most reliable and gave measurements consistent with weather data for a given place. This sensor has an integrated thermometer, hygrometer and barometer. The system tests lasted several months, including winter. All this time BME280 did not cause any problems.
Housing and solar power supply
The assembly of the whole system begins with cutting the plexiglass to the dimensions of the smaller housing. Then we need to drill holes in it with the same spacing as in the housing, through which we screw it to the housing.
After mounting in the electronics housing, we can determine the location of the antenna socket in the module. We can drill a suitable hole in the housing, and next to it two more - one for connecting the BME280 module and the other for connecting the DS18B20 temperature sensor.
Then we need to drill further holes in the plexiglass for the Sunny Buddy module, which must be located so that its mounting holes match the holes on the FeatherWing Doubler prototype board, as in the photo above.
According to https://learn.sparkfun.com/tutorials/sunny-buddy-solar-charger-v13-hookup-guide-" target="_blank" rel="noopener nofollow ugc" title="http:// https://learn.sparkfun.com/tutorials/sunny-buddy-solar-charger-v13-hookup-guide-" class="postlink inline-block "> connection instructions solder on the converter module screw connectors in places marked "Solar In" and "Load". Then we can mount the inverter to the plexiglass using sufficiently long screws to enable assembly of the prototype board with suitably long distributors.
After assembling this part of the device in the housing, mount the SMA socket on the appropriate adapter and place the battery in the housing. The antenna cable will run next to the Sunny Buddy to the LoR transceiver.
We can now mount cut plexiglass in the housing together with the other modules.
We connect the battery to the JST connector marked "BATT" on the solar converter module. The cables from the solar module are connected to the pre-soldered screw connector on the converter module, remembering about the correct polarity of the input. Connect the cable with the JST-2 connector to the "Load" connector on the Sunny Buddy, remembering that the red cable goes to the plus and the black to the minus in the socket.
At this stage, the module is ready to mount the prototype board and LoR transceiver.
Installation of the radio transceiver and prototype board
The uFL socket for the antenna is soldered to the 32u4 RFM95 module https://learn.adafruit.com/adafruit-feather-32u4-radio-with-lora-radio-module/antenna-options" target="_blank" rel="noopener nofollow ugc" title="http:// https://learn.adafruit.com/adafruit-feather-32u4-radio-with-lora-radio-module/antenna-options" class="postlink inline-block "> according to the instructions .
The female sockets that are delivered with the FeatherWing Doubler prototype board are assembled on one half of the board, as shown in the picture above. The other half will remain unused. Then solder the connectors on the board,as shown in the picture, to connect the power supply (3.3 V and GND) and I2C signals - SDA and SCL - to the socket for the BME280 module.
Next, solder on the prototype board another connector, dedicated for DS18B20. Connect the power supply (3.3 V and GND) and the output from digital pin number 5 (this will be our 1-Wire interface) to the connector for this sensor. Pass the sensor cable through the previously prepared hole in the housing and solder the connector to it, which we plug into the socket prepared on the prototype board.
Finally, we can gently plug the adapter into the antenna socket, the other side of which is screwed into the housing to be able to attach the external antenna.
The assembly of this module is completed by plugging the prototype board into the Sunny Buddy module and assembling it necessarily using spacers, so that the components of both modules do not touch each other.
Now we can upload the software to the board. Once done, we can connect the Feather module to the prototype board. Do not connect the cable with JST connector from the "Load" output of the Sunny Buddy module at this stage. Later we will connect this cable to the port where the battery is normally connected to the Feather module.
After assembly, seal the cable openings in the housing with silicone. Thanks to this, the housing will be tight.
Shield Solar Radiation
Let's follow http://www.davisnet.com/product_documents/weather/manuals/07395-093_IM_07714.pdf" target="_blank" rel="noopener nofollow ugc" title="http:// http://www.davisnet.com/product_documents/weather/manuals/07395-093_IM_07714.pdf" class="postlink inline-block "> assembly instructions for this module . Then install this module as shown in the photo above. On https://learn.adafruit.com/adafruit-bme280-hu...pressure-temperature-sensor-breakout/assembly" target="_blank" rel="noopener nofollow ugc" title="http:// https://learn.adafruit.com/adafruit-bme280-hu...pressure-temperature-sensor-breakout/assembly" class="postlink inline-block "> Adafruit website we will find instructions for connecting this module with BME280. Then solder the protector to the prototype board.
Using the pictures shown above, combine together both modules using a prototype board. Using the cable pieces, connect the outputs from BME280 (VIN, GND, SCK and SDI) to the socket on the prototype board that we just soldered. Then we attach the pins from the FeatherWing Doubler module to it as follows:
3.3 V - VIN
GND - GND
SDA - SDI
SCL - SCK
The mounting holes on the Adafruit prototype board have the same spacing as the shield dedicated to monitoring sunlight. Thanks to this, it is possible to easily connect everything with a few screws.
In the picture above one more row of female pins is visible. They were used during initial experiments with the system, aimed at selecting the best sensor - they are not needed for normal operation of the system.
Then we cut a piece of plexiglass, as shown in the photo - the cut fragment should be the width of the solar panel, but long enough for it to be screwed together with the panel to the appropriate shield. After installing the module prepared in this way, it will be slightly inclined, thanks to which it will be better to collect sunlight during the day.
In the plexiglass, we drill holes for mounting the photovoltaic panel and a dedicated shield for it, and we turn everything together, as in the photo above.
At this stage, we can connect the rest of the system to the "Load" connector to the Sunny Buddy module. The cable with JST connector is connected to the battery input of the Feather module. The weather station should immediately turn on and start broadcasting - every 10 minutes it should send a report with the measured parameters to the LoRa gateway in our system. The assembled measuring station has been working for the author of the project since October 2016 - it survived the winter without fail.
Step 4: LoRa IoT base station user interface
The menu displayed on the LCD screen of the base station presents a simple user interface controlled by four buttons we installed earlier in it. This menu allows you to easily add or remove functions from the system.
The interface is operated by four buttons: Func, Enter, Up and Down. The exact operation of the user interface is contained in the documentation in PDF files for download on the project website.
The interface has a number of options:
1. Turning the LCD backlight off and on.
Turns off the LCD backlight. After turning it off, just press the Func key to turn the backlight on again.
2. Display mode configuration.
Configures how the data is displayed in the second line of the display. There are three operating modes, each of which can be configured to display temperature or humidity, which together gives six options for data presentation.
The screen can display the latest data from the station that last sent the report, data from only one station or alternately from both.
3. RSSI display
RSSI is a signal strength indicator. It allows you to display the strength of the signal received by the LoRa transceiver from each station. After the station list, scroll with the Up and Down keys.
4. Battery status display
Displays battery voltage - the supply voltage of each of the 32u4 RFM95 transmitters in our LoRa network. On the station list, scroll with the Up and Down keys.
5. Setting alarms.
This function allows you to enable and disable alarms and configure their level. In the current version of the software, alarms related to high humidity, low battery and loss of contact with the station are available.
6. Setting humidity alarm level.
This function allows you to configure the humidity level for each station separately.
7. Setting the number of measuring stations.
By default, the system starts with one active station. A maximum of ten independent measuring stations can be connected to the gate. The number of stations must be configured before we can start using the next option - the function of giving stations unique names.
8. Setting station names.
Allows editing station names. The name can have up to nine characters.
9. Time setting - winter / summer.
It allows you to set whether the change from winter to summer time and vice versa is enabled or not.
10. Time zone setting.
It allows you to configure our time zone. Identified by the main city located in the given zone.
11. Setting the pressure sensor calibration offset.
It allows you to configure a constant pressure offset related to the height of the measuring station. Let's configure it so that the pressure values are the same as in the data available on meteorological portals in our area.
12. Choice of temperature units.
It allows you to choose in which units the temperature is given: degrees Celsius or Fahrenheit.
Step 5: Notifications and alerts via SMS
The pictures above show notifications and alerts sent with the help of text messages (SMS).
Notifications are sent via SMS about every hour. The LoRa base station is configured to send SMS to the indicated number half an hour after every equal hour. 160 characters can fit data from four measuring stations (temperature and pressure).
The content of the notification depends on the content of the sendStatus () function in the Temboo module software in the base station program code.
The alarm is sent via SMS when the selected parameter exceeds the programmed threshold. Alarm levels are set for each station separately. The SMS format is defined by the sendAlert () function in the gateway software.
SMS messages are sent via the email gateway to the operator's SMS. For the major US mobile operators, the email address is configured as follows:
AT&T: [10 digit phone number] @ txt.att.net
Sprint: [10 digit phone number] @ messaging.sprintpcs.com
T-Mobile: [10 digit phone number] @ tmomail.net
Verizon: [10 digit phone number] @ vtext.com
Sending an email to the provided address will cause the user of the given 10-digit telephone number to receive an SMS. Email addresses for our operator can be found on the Internet. The phone number is stored on the SD card in the system.
To send emails from the gateway, an Temboo account and Gmail address are required. On the Google website, we configure email and Google Drive, also used by the system (see below). Then on the Temboo website we set up the account - for 30 days the account is free, then we have to pay a small fee.
On Temboo, we configure Google Gmail SendEmail Choreo, which allows you to send email via Gmail. The credentials for logging into the Temboo service are saved to a file on the SD card.
Step 6: Storing data in the cloud
The image above shows how the data collected by individual measurement modules are collected in a spreadsheet on Google Drive. Data is sent from the base station to Google Drive every hour, about two minutes after each full hour.
The first column shows the time when the entry was sent. If it is midnight, the time is replaced by the date. The content of further columns in Google Sheet is defined by the content of the spreadsheetUpdate () function in the program related to the Temboo functions. If we want to save data from a larger number of measuring stations or modify the format of stored data in any way, it is in this piece of code.
You need a Temboo account to transfer data to Google Drive from our LoRa IoT base station. As described above, we first set up a Google account, then set up a Temboo account and configure it. We will obtain account verification data by creating a Google spreadsheet under the name AppendValuesChoreo. We'll find more information about authentication later in the text.
Step 7: Web application panel
The image above shows the AdafruitIO panel, showing in real time the status of our installation and the results of measurements. The data presented on the web is updated every three minutes.
The AdQruit MQTT queuing system client is included in the software for the LoRa IoT gateway. This client publishes data streams through AdafruitIO, which acts as a queued information broker. Each data stream - feed - is responsible for one parameter from one device, for example temperature from an external sensor. Adafruit provides the right tools to create a Web page that displays this data in a configurable way.
Adafruit has published very good tuto rial describing the creation of an Adafruit account and the configuration of data streams and their display on AdafruitIO. The system is currently in beta testing and limits the number of data streams to ten.
In the LoR gateway program of our system, the login details - username and password - are stored in the AIO_Account.h file:
Code: text
After changing this data, you must re-compile the gateway program and load it into the system.
In subsequent versions of the software for LoR IoT deficiencies, the author plans to store the above data together with login data for Google and Temboo services on an SD card, so that no recompilation of sources will be needed.
Currently AdafruitIO does not work perfectly stable - the connection breaks after about 24..48 hours of work and it is not possible to reset from the device. But, as described above, this system is only in the beta stage. This does not affect the operation of other LoR gateway functions.
The author plans to incorporate the Web server into the device in future versions of the software, thanks to which the website will be presented without the need to use the MQTT queuing system and connection with AdafruitIO. Implementation of this task - creating an HTML5 page with JavaScript - should be within the reach of Arduino Mega.
Step 8: LoRa IoT gateway software
The source code for the gate is available on the project website. It is written in a rather procedural style and has a lot of comments, which should make it easier to edit and understand. The repository with all soft can also be downloaded from github .
In the current version, the only user change required is the addition of login credentials to the AIO_Account.h file, as described above. All other options are configured in the system through the gateway user interface, and the authentication data for logging into Google and Temboo is contained on the SD card.
Below you will find a general description of the source code and what it contains.
Setup
The code contained in this part initializes the individual Arduino pins for communication with the systems in the gate, initializes the SD card, LCD and initiates the sequence of initialization of individual peripherals in the system.
eepromRead ()
The first time the gate is started, the system saves to the EEPROM the default settings, each time it is started it is read from that memory. They can be changed from the user interface. A message on the LCD will indicate whether the data has been read from the Arduino or the default has been uploaded.
RFM95Initialize ()
This procedure performs a hard reset of the LoR transceiver and then initializes it by configuring to work with 915 MHz with +23 dBm transmission power (although Tx is not currently used by the gateway). In future versions of the software, the transmission frequency and transceiver power will be set through the gate's user interface.
ethernetInitialize ()
Procedure initiating connection to the network via Ethernet. The system will work as a DHCP client, so the router should give IP to the gateway, which will display it on the LCD.
readGatewayData ()
Reads login data for Temboo and Google services from the SD card.
sendStatus ()
It sends an SMS with a notification containing empty data fields - allows you to check whether authentication in the Temboo and Gmail services is working.
spreadsheetUpdate ()
Updates the content of the Google spreadsheet in the Drive service with all zeros, which allows you to verify that the authentication in the Temboo and Google Drive services works correctly
AIOconnect ()
Connects to the AdafruitIO MQTT broker, which allows you to verify that the authentication in this service works correctly.
Main program loop
The main program loop - loop () - performs the following actions sequentially:
First, it is checked if the Func button has been pressed, if so, Function () is performed, which performs procedures related to the user interface on the gate's LCD. The program then launches the systemTimeUpdate () function, which updates the system time; if at least a second has passed since the previous iteration of the program loop (i.e. the second counter increased), the program performs the following operations:
Checks whether the number of seconds is equal to the configured time at which the defined operations are performed every minute. For now, two such operations are defined - in zero seconds of every minuteAdafruit MQTT data broker ping system, and in 50 seconds every minute updates the second line of the display, as recorded in its configuration.
The next steps are procedures that are repeated over a long period of time:
Every 10 minutes, the system publishes data in the AdafruitIO stream and checks whether there is a need to send a predefined alarm SMS.
Every hour, two minutes after the full hour, a data update is sent to Google Drive. Three minutes after a full hour, the system updates its time using the Network Timing Protocol (NTP). Four minutes after a full hour, the system checks the connection to Adafruit MQTT - if it does not work, it tries to reconnect to this service.
Half an hour after the full hour, SMSes are sent with notifications that contain information on measurements, etc. 40 minutes after the full hour, the system re initializes the LoRa radio system. It is required by the fact that during such a long work LoR transceivers can hang up etc, and re-initializing them every hour, at a constant and controlled time, causes that this type of problem does not occur.
After performing cyclical operations, the system checks whether the LoRa transceiver has received any data packages from the measuring stations, if so, it begins processing them and updates the data displayed on the LCD screen in the second line in the latest measurement presentation mode.
Interrupt support
The LoRa gateway uses one interrupt, which is related to pressing the Func button in the user interface. Thanks to emu, when the menu control button is pressed, the system will terminate the currently implemented function and perform functions related to the operation of the user interface. The interrupt has been configured so that it will be disabled when the user interface function starts.
After returning from interruption, the system starts NTP, which allows you to update the system time to the current time,
RFM95W radio network functions
getRadioPacket ()
The procedure is started when the LoRa radio in the core network receives a data packet from an external station. This procedure appends the signal strength and arrival time of the data packet to the appropriate matrix, and of course reads it.
checkAlerts ()
The procedure runs in the main program loop every ten minutes. If any of the defined situations occur - loss of connection to a remote station, high humidity level or low battery level, this procedure will start sending an alarm SMS.
Temboo procedures
sendStatus ()
Procedure that generates a message to be sent via email gateway to an SMS. By default, the software is configured to send humidity and temperature data in the first four measuring stations in an SMS. If we want to change the content of the SMS notification, this is the procedure we are looking for.
sendAlert ()
A procedure similar to the one above that generates an e-mail to be an SMS alarm. It is activated when a defined alarm situation occurs. The content of this procedure should be changed if we want to change the content of emergency messages.
sendEmail ()
A procedure, generated by Temboo, for sending emails via Temboo Gmail Choreo.
spreadsheetUpdate ()
Updates the data compacted in the Google spreadsheet - an update is sent via Temboo Append Row Choreo, which adds one row to the spreadsheet on Google Drive. The content of this function should be modified if we want to change the way of sending data to Google spreadsheet or its format.
sendSpreadsheetUpdate ()
Code, generated by Temboo, for sending data to Google Drive via Temboo.
Functions dedicated to timing
systemTimeUpdate ()
Counts the seconds of local time. This function also updates the time displayed on the LCD (in HH: MM: SS 24h format).
ntpTimeUpdate ()
This function, called every hour from the main program loop, locates with the time of the local network gateway - uses the getNTPtime () function to get the current time, locates it taking into account the time zone and summer / winter time, and then displays on the gate screen, after correctly obtaining the time after NTP.
EEPROM functions
Functions related to EEPROM memory support are responsible for initialization, saving and reading data from this memory. Data in the EEPROM memory are saved in the form of the structure shown below. The readBlock () and updateBlock () functions from EEPROMex.h are responsible for reading and writing data in the form of such a structure to EEPROM, respectively.
To extend the life of the EEPROM memory (which has generally quite a limited number of write and read cycles), the data saving function - updateBlock () checks before saving if it will make any changes to the memory; if not, it does not physically overwrite the data.
The use of the data structure to store data in memory has a great advantage - in the future it allows easy modification, if anyone wants to add additional data to memory. The structure at the current stage of LoRa gateway software development is as follows:
Code: c
Functions related to the operation of the LCD display and menu closing buttons
An enumerator (defined below) is used to index items in the LCD interface menu. By using the enumerator, there is no need to watch the numbering of individual options in the menu when adding more items. The enumerator starts with the entry "START_FUNCTIONS" and ends with "END_FUNCTIONS." Thanks to this - regardless of the number of options between these elements in the enumerator, the program always knows when it hits the beginning or end of the menu. The enumerator is defined as follows:
Code: c
Every time you press the Func button, the program goes into a while (1) loop. Being in this loop, the program monitors pressing all four buttons. Their functions are:
FUNC - Causes you to exit Function () and return to the main program loop.
ENTER - Executes the currently displayed option in the menu.
UP - Scrolls the displayed option one step up.
DOWN - Scrolls the displayed option one step down.
After entering Function (), each time you press the Up or Down button, functionDisplay () will be performed, which changes the menu function currently displayed on the LCD. Similarly, after pressing Enter, functionExecute () will execute, which executes the given function from the menu.
Thanks to the presence of the data structure, adding new entries to the menu is very simple. Similar structures are used, for example, to describe the LCD operating mode during normal operation of the LoRa gate. A more detailed description of the data display modes is provided in the part of the article describing the user interface. The data structure describing the LCD display modes is as follows:
[Syntax=c]enum {
START_DISPLAY_MODES,
LAST_STATION_TEMP,
LAST_STATION_HUMI,
FIXED_STATION_TEMP,
FIXED_STATION_HUMI,
CYCLE_STATION_TEMP,
CYCLE_STATION_HUMI,
END_DISPLAY_MODES
};[/syntax]
The display also has a data matrix for display that the enumerator indexes:
[Syntax=c]const char* DISPLAY_MODE[] = {
" ",
"Last Stn Temp",
"Last Stn Humi",
"Fixed Stn Temp",
"Fixed Stn Humi",
"Cycle Stn Temp",
"Cycle Stn Humi",
" "
};[/syntax]
This technique was not used in more places in the program, although it could, because it allows to save the system's RAM. A more detailed description of the use of such structures in the program can be found here .
SD card operating procedures
Procedures related to the support of the SD card allow you to write and read data from this card in the LoRa gate, The readGatewayData () function reads from the SD card previously stored data for authentication in the Temboo and Google services. These data are saved in the GW_Data.txt file. More about the structure of this file below.
GW_Data.txt files contain text limited by square brackets, so we assume that there are no such brackets in the password, etc. If you need to use other characters to restrict the texts in this file. This function reads data into the gatewayData string matrix [12]. Individual elements of the matrix are described by names from the following enumerator.
Code: c
Thanks to this type of structure, further entries can be added to these data if needed.
LCD operating procedures
The updateStationDisplay () function is responsible for generating the lastStationDisplay string, which contains data to be displayed in the second LCD line. This string is generated according to the display mode settings. Each time any function updates the data status, the lastStationDisplay () function is used to update the content of the string to be displayed on the LCD.
To simplify LCD operation, a number of functions are used for simplicity:
* updateDisplayLine12 (String Line_1, String Line_2) - updates lines 1 & 2
* updateDisplayLine1 (String Line_1) - updates line 1 leaves line 2 intact
* updateDisplayLine2 (String Line_2) - updates line 2 leaves line 1 intact
* clearDisplayLine1 (String Line_1) - clears lines 1 & 2 and updates line 1
* clearDisplayLine2 (String Line_2) - clears lines 1 & 2 and updates line 2
Step 9: Software for the internal measuring station
LoRa network measuring stations - internal and external - are generally called remote stations. Each remote station has its unique ID number, so it can be correctly identified by the LoRa gateway. The identification number is rigidly stored in the software of each remote station. If we want to change this unique identification number, we must recompile the software for the given station again.
In the current version of the software the number of identification numbers in the system is rigidly limited. The ID can be from 0x00 to 0x09, which gives 10 stations. In future versions, the station numbering is to be done automatically by the gate after connecting to the station. Thanks to this, it will be possible to add more stations to the system in a completely seamless way.
The libraries provided by Adafruit are used to initialize and read data from the SHT31 sensor. In addition to the data read from this sensor, the station also sends other data to the LoR gate. They are sent in the form of the data structure shown below:
Code: c
The above data union allows you to map floating point values to bytes, so you can transfer them via the wireless interface. Similarly, other types of variables, such as thongs, can be sent. The number of sent variables can be increased - just add them to the structure described in more detail below.
The indoor weather station sends information about the air temperature (airTemp) and supply voltage (bat volt) to the base station. In the case of an indoor station, the supply voltage is taken from the supply voltage to the Feather module. Other data, such as ground temperature (gndTemp) or pressure (pressure) are set to zero.
The size of packets sent via the wireless network is 5 float variables (5 bytes each) plus one byte for the station ID number - 21 bytes in total. The LoRa network packet is built through the buildWirelesspacket () function, which uses binary variable mapping as follows:
[syntax=c]for(int n=0; n
Cool? Ranking DIY