Saturday 30 January 2021

IOT: Data from Arduino to Raspberry PI

In this step, I'll send data from Arduino to Raspberry PI. 

When the user activates the emergency function, a signal will be sent to the RPI that will take a photo and publish on a web server. You can find more information about the traffic lights project here.

Step 1: Connecting Arduino to Raspberry PI

The RPI is connected to a camera module.
A USB cable connects power and serial from the RPI to the Arduino.


The first step is to find the serial port. For the RPI, I've compared the tty ports without and with the Arduino.

The interface /dev/ttyACM0 shows up when I connect the Arduino over USB.

I uploaded a small python script with code that I found on DiyIOt from my Windows computer to my Raspberry PI.

I added a couple of lines to take a photo on the webcam


Step 2: Take a picture, if the emergency button is pressed.
The script checks if the message matches the expected string. If it does, the script will ask the shell to take a photo and save it in /var/www/html/ folder.

When the RPI detects "Switch to Emergency", it captures a JPEG image.
In order to reduce the download time, I've selected a lower resolution than the 3280x2464 that is supported.

Step 3: Publish the image on the web server
The /var/www/html folder is owned by root. This makes it hard to save files there automatically. To resolve this, I've changed the ownership and permissions for that folder. 

A very simple web page that reloads every third second shows the picture. Code and screenshot below:

The updated webpage looks like this:

Now, an event on the Arduino can trigger the RPI to take a photo and show it on an internal web page. The next step will be to send some feedback from RPI to Arduino and to explore video streaming from RPI.





Saturday 23 January 2021

IOT: Bringing Up a LTE Based Wi-Fi

As a Christmas gift, I purchased a TP-Link Archer MR600 LTE/4G router to a close relative to use at his vacation home. 

The radio conditions there are a bit challenging, with a concrete house on the northern side of a ridge, 1.3 km from a base station. The metal reinforcement bars in the concrete act as interferers, cancelling out 4G signals.

The router supports several LTE bands, including the coverage bands (8 and 20) and the capacity bands (3 and 7). The former bands have lower frequencies, which gives bigger coverage but lower performance and are suitable for rural areas. The latter bands have higher frequencies which gives smaller coverage but higher performance and are suitable for urban areas.

I tested the modem in my house in Åkarp with satisfactory results (RSRP: -100 dBm for Band 3 and 7). In the summer house, the signal was barely detectable.

I found a discussion on TP Link's forum where another user had the same issue. The support told that there was a firmware version that supported band selection, and I installed that on the router. After that, I was able to register to band 8.

A 4G router that doesn't allow the user to select band is a quite lousy router. Fortunately, it was possible to overcome that with another firmware, but that shouldn't be necessary.

Saturday 9 January 2021

IOT: Setting Up a Web Server

With a toddler and a newborn at home, my pet projects will progress at a slower pace. Expect one or two blog posts every months.

So far, I've brought up a Raspberry PI 3 B into headless mode with a camera. I've also bought a 4G modem to a summer house that a close relative has. This will provide Wi-Fi connectivity for later deployments of IOT projects.


The next step is to bring up a web server on the RPI that shows the last pictures from the web camera.


Saturday 2 January 2021

2020 in Retrospect

2020 was a dramatic year for me and that had some impact on my pet projects. 

The first wave of the pandemic came when I and my family moved to our current home in Åkarp. Luckily, that didn't affect the relocation and the contractors we used for fixing things in the house.

We got our second son when the second wave was escalating in December. 

The pet projects still had some progress:

StockPredictor (C#, Python, SQL and Machine Learning): I created a Python script that connected to the SQL database and analyzed the data, for example identifying stock splits. I also made some improvements to the web scraper. After several months of work with the data, I was able to apply some machine learning algorithms to the data. As expected, the MLPRegressor wasn't able to predict future stock values - it seems that the market is quite efficient.

IOT (Arduino, Raspberry PI): I explored Arduino and followed some simple experiments to learn the basic concepts. After that, I created a simple set of traffic lights with an emergency button and a LCD display. For Raspberry PI, I brought up the system.

In 2021, I'll mainly focus on the house, work and family.  I still think I can have some progress on my pet project in IOT.