# Weather station for remote greenhouse #### *Author* Rasmus Allansson, ra222pr ### Introduction The weather station is a FiPy with Pysense connected over LTE. The station measures temperature, humidity, atmospheric pressure and light. The data is published on Ubidots and contains a trigger to notify by email when the temperature rises to high. Approximation of expenditure of time: 5-20 h depending on how much struggle you have establishing an LTE connection. --- ### Objective The purpose of this project is foremost to be able to see the current temperature in a greenhouse located around 200 meters from the dwelling house. In this way the need of walking down to the greenhouse just to see if the temperature is right is eliminated. The ability to track different parameters such as temperature and humidity also helps in learing what climate best suits each type of plant. If some plants seem to thrive and some not we can look at the collected data and see how the climate has been for the past weeks trying to learn what works best for each plant. This is the main reason why I chose to build this project. --- ### Material #### *List of material* | Parts | Price | | -------- | -------- | | Pycom FiPy | €54.00 | | Pycom Pysense 2.0 X | €26.95 | | Pycom LTE-antenna | €9.00 | | Micro USB charger with detachable cord | €1.00 and up | | IoT SIM card | €25.00, €3 a month | | Web service: Ubidots STEM | FREE | | Computer running Atom | | | ***Total, vat and discount included*** | **Approx. €130** | The Pysense is packed with four different sensors. They are called as followed: LIS2HH12 - Accelerometer LTR329ALS01 - Light MPL3115A2 - Altitude & Pressure SI7006A20 - Temperature & Humidity These are all third party sensors. To find the datasheets for them, simply Google the sensor names. In this project we will use the last three of them. What is important to realize regading the sensors is that they are all communicating over a seriel based protocol by the name of I2C. Feel free to read up about what this means. Luckily Pycom has written a library for each sensor which are all included in the project files later in this tutorial. ![](https://i.imgur.com/reJ4CbX.png) #### *Cost* The Pycom hardware was ordered from pycom.io for the price of €103.15 VAT include. As most of us I had a Micro USB charger from an old phone laying around, but these can be found almost anywhere today from just a couple of euros and up. My IoT SIM card of choice was Telenor’s Smart Uppkoppling (Clever Connection) with a startup fee of €25 and approximately €3 a month with the first year for free. It can be found at their own store or online. Total price: Approx. €130 for the first year, then €3 a month. --- ### Computer Setup Please note I’m running macOS Version 10.14.5, so there are things that will have to be done differently on other operating systems. At the time of writing there is no firmware update released for the Pysense 2.0 X, and therefore we can go straight onto updating the FiPy. Before we can do that, we have to put the components together as explained in Putting the hardware together further down. To be able to update the FiPy you need to install “Pycom Firmware Update” on your computer. Latest version of the program can be found [here](https://docs.pycom.io/gettingstarted/installation/firmwaretool/). Once installed, start the program and follow the instructions. You should not need to check any boxes in the process. Now you’re ready to move on to the IDE. If going for the same IDE as I did, start by downloading the latest version of Atom from www.atom.io. Ones installed on your computer, start the program and from the Welcome Guide choose “Install a Package” > “Open Installer”. Search for and install “pymakr”. This extension will make Atom able to talk to your device while connected and will make the entire process off coding easier. You’re now ready to start coding. How the project is uploaded to your device you'll find out if you keep on reading. * Download “Pycom Firmware Update” * Flash latest firmware on FiPy * Download and install Atom * Install pymakr plugin in Atom --- ### Putting the hardware together Because of the choice of using the Pysense I eliminated the need of using any loose sensors, breadboard and wire. Everything needed is included in the Pysense, so all I had to do was to insert the SIM card and attach the antenna to the FiPy, connect the FiPy to the Pysense and adding power supply via the Micro USB charger. If you don’t have an electrical outlet in access to the hardware you can easily connect a LiPo battery to the integrated connector on the Pysense. On [Pycom's website](https://docs.pycom.io/gettingstarted/connection/fipy/) you find how all the connections should be done. To go with the Pysense means you don't have to do any electrical calculations and don't need to do any circuit diagram to keep track of the connections. The only downside as I see it is that you can't put the FiPy in an enclosure without affecting the measured values. This is mainly a problem of aesthetics and if you intend putting the device outdoors. * Put your components together as explained in the above link --- ### Platform Since this greenhouse is shared by around 20 people, I wanted to make it easy for everyone to access the information without the need to create an account. The platform had to be easy to reach and understand for the end user. I also wanted to add the possibility to get a notice when the temperature fell out of a given span to minimize the need of checking the webpage or app. A requirement for the platform was that it was free. Adafruit IO is a good candidate as it has barely any restrictions but lacks in widgets and design. It just doesn’t look good. Ubidots STEM on the other hand has really good widgets and the design is good looking, but unfortunately it has restrictions of for example how much data can be sent to and be retrieved from the server as well as maximum number of emails sent each month. If you're planning on sending video and pictures this probably isn't for you. I also took a glance at other platforms but felt most of them to be looking old, cheep and/or lacking in functionality. I personally decided to go for Ubidots, mainly for the design, although there are certainly better options available out there where you get less restrictions without compromising on design. When choosing for your own project, think about your needs and what’s most important for you. The following will explain how to do if choosing Ubidots. Go to ubidots.com and sign up for an account. In your Ubidots account, first create a Device. You do this by clicking: `“Devices” > ”Devices” > + (plus) symbol.` When it comes to the variables in Ubidots you have two choices; either you create them from the website upfront or you let the server create them for you as the first publishing is done. On your device’s site, simply click “Add Variable” and choose type. When created, click the variable to configure it. “API Label” is the most important parameter as it’s the name you have to put in your code later so the server knows where the data should be sent. To create a dashboard, click “Data” and choose “Dashboards”, then make your own design. [This](https://www.youtube.com/watch?v=IK_ykCk_Os8) video gives you a good foundation of how it’s done. * Go to ubidots.com and sign up for an account * Create a device * Create variables * Create a dashboard --- ### The code All the files you need to upload to your devices can be found [here](https://github.com/rasmusallansson/weather-station). Download the map "Weather station greenhouse" and open it in Atom. All the information regaring what the code does is supplied as comments directly in the code. To be able to connect to Ubidots you have to replace keys.ubidots_token() in the main.py with your Ubidots Token. You find it under Token on the left side of the screen when viewing your device in your Ubidots account. If you instead like to use the given function, in the folder lib, make a new file called keys.py. Copy and paste the following code into the file and insert your Ubidots Token where stated, but keep the quotation marks. ``` def ubidots_token(): return "replace-this-with-your-Ubidots-Token" ``` As the FiPy is connected over LTE it can be a bit tricky to get it working if on a different operator or subscription plan than me. What you need to do is contact your operator of choice and find out their APN. That is the web address to the server giving you access to the internet. You also might need to exchange the file telenor.py to a file from your operator. The easiest way of knowing is foremost to try the file with your operators APN. If not working, contact the operator or search the Internet for help. Note that if you’re intending to put your Ubidots Token straight into main.py the line “import keys” has to be erased. Otherwise the code will not work. At this point you should have a fully working weather station sending data to Ubidots every 5 minutes. * Download library from link above * Open library in Atom (Shift+Command+O and choose the folder) * Replace keys.ubidots_token() with your Ubidots Token * In telenor.py, change the APN to the one given by your operator of choice * Upload project to your FiPy (Control+Option+S) * If it won’t connect to LTE, try and exchange the telenor.py file --- ### Transmitting the data Because of the location of the greenhouse I had two choices of connectivity to choose from. The first being with two boards, one in the greenhouse and one in the dwelling house connected over LoRa with the latter acting as an access point between the greenhouse and the WiFi Router. The other alternative, the one I chose for flexibility and financial reasons, is as already mentioned a FiPy connected to the internet over LTE. This did fit my needs better as this project is just temporary and the hardware will be used in other remote places afterwards where LoRa simply won’t work. The data is sent every 5 minutes using the MQTT protocol. It would have been possible to lower the amount of transmissions, but I decided the accuracy and up to date of the data was more important. Since the information sent is of very small size, I also wanted to use a lightweight protocol to minimize power consumption. I was looking at was HTTP but rolled it out for the sake of speed, battery consumption and data rate. CoAP, another alternative, is a node to node protocol meaning if a node is turned off the information will get lost. In MQTT, as a node to broker protocol, the broker is always on meaning the information will be saved at the broker so the receiving node can fetch it when connected again. It’s therefore well suited for unstable connections. --- ### Presenting the data The dashboard on Ubidots exists of four graphs each representing a parameter receiving new data every five minutes. As standard the data is saved for a month on a Ubidots STEM account. For each parameter there is also a widget showing the most resent value. Each parameter is given its own representation format to make it more interesting. For example, the temperature is displayed in the format of a traditional analog thermometer and the atmospheric pressure in a round container showing half full when “normal” pressure to raise and sink as the pressure changes. A trigger is also setup to send out an email when the temperature rises above 35 °C for 15 minutes. Another trigger does the same telling when the temperature falls below 15 ºC. The reason to not have it sent out immediately is to ignore any short variances in the temperature that might occur in a greenhouse. A third trigger notifies when no data has been recieved for 15 minutes. For the sake of interest, I also included a map showing the location of the greenhouse. I was also looking for a way to let anyone easily choose to subscribe and decide what time and days to do it, but didn’t manage to find that service for free. The big As I didn’t want to build my own server to minimize maintenance the obvious choice was to use an online service. Since Ubidots has its own database, or at least don't give you the option to choose for yourself, I had to go with the one provided. This is how my dashboard looks an a computer: ![](https://i.imgur.com/WkTO7Zf.png) ![](https://i.imgur.com/n8MSbmZ.jpg) * Dashboard contains four graphs, four widgets showing the most resent values and a map of the location * Receives data every five minutes * Data is saved for a month * An email is sent when temperature rises above 35°C for 15 minutes --- ### Finalizing the design Over all this project turned out approximately as hoped for. The hardest part was to get it connected to LTE as there is still not that much information on the Internet about it, and it's not as universal as connecting over WiFi och LoRa. When it comes to data presentation I'm really happy with the result. It looks clean, simple and professional. The big downside as described earlier is the restrictions of data amount and maximum number of emails sent each month. If you like to have more control over the data one could build there own database and server, but this requires extra hardware and infrastructure to support it. A nice feature to add to this project is to have a backup battery combined with a sensor recognizing when the main power supply fails. You can then setup a trigger to alert there is a potential power failure in the house that needs to be fixed. Another nice thing to do when Pycom releases its wireless sensors is to put up sensors in different parts of the greenhouse and even adding sensors for measuring the humidity in the soil so you know when to water. Unfortunately the device isn't in the greenhouse at the moment, but at least I have a picture of how it looks put together. The intention is to mount it on the wall in a shadowed place close to an electrical outlet. ![](https://i.imgur.com/gVsJGcb.jpg)