A simple baby monitor that monitors temperature in a baby environment like a stroller or crib and sends data to a server.
This project has 2 parts, iot device and the backend-server which the iot device connects to.
(iot device)
should take approximately 10 hours depending on complexity.(backend-server)
depends on what implementation is chosen. You can choose a pre-existing platform to publish your data and this should take about 2 hours to setup. You can choose to build your own backend server and that could take about 30 hours.So my first son was born recently and I had to buy one of these baby monitors that allows you to monitor the baby while they're asleep. I became interested in transmitting the temperatures over the internet to I could analyze and visualize the data overtime.
This project serves the purpose of reading temperature values from a baby environment like a stroller or crib and then sends the data to a server which in turn analyzes and visualizes data.
A valuable insight this project can give is a visualization of what temperature a baby sleeps at best or inversely ie what temperature are the toughest for the baby to sleep.
Lopy4 with headers (394.04 kr)
This device is programmed with Micropython. It works with LoRa, Sigfox, WiFi and Bluetooth and is an excellent choice for an Iot project.
Expansion Board 3.0 (180.37 kr)
This board allows you to connect important parts that are needed to make the lopy4 device work. Parts like power, battery and jumper wires.
Breadboard(400 Connections) 59.00 kr
This allows you to connect your sensors, jumper wires etc in an easy way. It's very practical and makes connections easier.
Temperature Sensor(MCP9700A) 15.00 kr
A simple temperature sensor. This is connected by a pin on the breadboard and the value is read and can be manipulated to get temperature values.
Jumper wires
Simple wires for connecting sensors from the lopy device to the breadboard.
Ultimately you can buy a bundle from electrokit which contains all you'll need for this project here.
All material listed where purchased from electrokit
Macbook pro/macOS Big Sur. See configuration in the image below.
The easiest way code is uploaded to the device through pymakr. Pymakr allows you to right click on the project and select upload to device
It's possible that you may be using a different Operating system and all the steps listed above may not cover your particular Operating system. https://pycom.io/wp-content/uploads/2020/04/Lesson-2-Pymakr-Set-Up-FiPy.pdf gives you relevant information on setting up from pycom itself.
These instructions are only valid if you intend to develop and run the backend solution that I've built on your computer. There is a working demo available on https://iot.ebrinktech.com.
git clone https://cinch-remit@bitbucket.org/cinch-remit/iot-backend.git
:information_source: you need to have installed git to be able to clone the repository.
For this stage, you'll need 3 jumper wires(preferably 3 different colours. I picked white, green and blue), the breadboard, the sensor, your lopy4 devices and the expansion board.
breadboard connections
See the image below for clarity
lopy4 connections
iot-backend server
(Optional)In order to be able to transmit data to the server you need to do the following
POST
request to this endpoint /v1/device/register/{deviceId}
.PUT
request to this endpoint /v1/reading/register/{deviceId}
. This endpoint takes the device name as a path variable.This endpoint requires json dataThis connection is currently in development stage. In the future, it might be soldered and probably the sensor will be updated.
When this project started, choosing the right platform was tough because there are so many awesome solutions out there. The most important factors were
After considering these factors, MQTT
using io.adafruit.com seemed like a perfect solution. Some of the functionality available on this platform are
Halfway through it seemed like a cool challenge to build my own dashboard and notification service and so the iot-backend server
(this is a working title) was introduced to the project. Some of the functionality the iot-backend-server
offers are
Code for the iot-backend server
can be downloaded and modified from https://cinch-remit@bitbucket.org/cinch-remit/iot-backend.git. Development will continue even after this course. Feel free to contribute :100:
If you're thinking about hosting the iot-backend server
, there are a few options that are cost effective
Heroku: This is a perfect startup place deploying your applications and for the most part, it's free. The downside is that your app goes to sleep when it's idle. So before you start transmitting to your device, you might need to visit the url just to 'wake up' your application. More information on https://heroku.com.
Digital Ocean(Kubernetes): This is a cost effective way to host your applications using kubernetes. I've provided manifest files in the container
folder found in the code but you'd have to setup an account on digitalocean.com, start up a kubernetes cluster and then apply the manifest files. Digital ocean gives you $100 free credits which are valid for 2 months. So you've got nothing to loose if you'd like to try it out. For some more advanced settings like linking to your own domain name(ingress
&& ingress controllers
), keeping your data intact even though you restart your application(persistent volumes
&& persistent volume claims
) or any questions about kubernetes in general feel free to contact me @rm222qf(rm222qf@student.lnu.se) or consult the https://kubernetes.io website.
Code for the pycom device can be found here https://github.com/achomgbah/iot-device.git
The code above has 2 functions,
isConnected()
checks if the device is already connected to a wifi networkconnect()
attemps to connect to a wifi network using the desired network name and password.The code above defines some variables which are important for sending data. Defining them as variables helps keep the code 'cleaner' and allows for easier editing in the future if things change.
urequests
: library used to handle https requestswifi_connect
: function to connect to wifiujson
: library used to format to and from jsonmqtt
: library used to handle all things mqttThese external libraries can be found and downloaded here
base_url
= this is the server address of the custom server which the device transmits data to.unique_id
= the devices's unique encoded iddevice_name
= the decoded value of the unique_idmqtt_host
= the MQTT
server addressmqtt_username
= login username for MQTT
servermqtt_password
= login password for the MQTT
serverLine 31 - 34 creates a connection to the mqtt server and subscribes to the desired topic.
Line 37 - 39 registers the device using its unique name to the custom server.
Line 44 - 45 collects information about the pin on which the sensor is connected.
Line 47 - 65 then uses the information collected from the previous lines and based on some calculations, it then gets a temperature reading. This reading is then sent to the custom server and finally to the mqtt data. Every temperature received is sent to the servers.
The api endpoints used on the custom are available on the demo server.
iot-backend
adafruit
adafruit
Overall this was a very practical project which was interesting all the way. Some of my reflections are as follows
iot-backend server
like showing current value, widgets for types of data and ability to send instructions to the device.iot-backend server
iot-backend server
login page
logged in landing page
device page
reading graph
io.adafruit.com
graph
last read value