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.

Saturday, 26 December 2020

AI: Colorizing Old Videos

It has been a couple of weeks since my last blog post, and that for a good reason (my second son arrived earlier this month).

I announced his arrival with some posts about some of his ancestors. One of the posts contained a video from the early 1950's.

There is a online tool (Jupyter/Python) that can colorize black/white photos and videos.

What It Does

DeOldify is based on Generative Adversarial Networks, where two Neural Networks compete to each other.  One Neural Network (generator) tries to produce realistic colorized pictures, and the other (discriminator) tries to tell whether pictures are authentic or colorized. The generator tries to fool the discriminator, and the discriminator tries to reveal the generator. When they work together, they will for example learn to create pictures that appear realistic to human beings.

DeOldify uses an extension of GAN that is called NoGAN. NoGAN eliminates some side effects of GAN for videos, for example flickering colors between frames.

You can find an interview with one of the inventors below.

How to  Use:

Step 1: I uploaded the black/white video file to YouTube. I wanted it to be available for deOldify but I didn't want it to be searchable yet, so I used the unlisted option. With the unlisted option, one needs the direct link to the video in order to see it.

Step 2: Follow the steps in deOldify Colab. One can run it in the cloud, or on a local computer, if desired. Provide the link to the video in step 1 when it is time to run the Colorize! step.

Step 3: The colorization can process a couple of frames per second, so this will take some time. Once the colorization is done, download the video file to your computer.

My original video:


My Colorized Video:

I added a small watermark in the lower left side of the video to indicate that this video has been post processed.



Saturday, 5 December 2020

IOT: Setting Up a Web Camera for a Headless Raspberry PI

In my IOT project, I need to take pictures with a headless Raspberry PI. 

The camera that I use today is an  USB 8$ web camera with a picture resolution of 640x480. It is a temporary solution - the official camera module v2 supports a resolution of 3280x2464 pixels and weighs only 3g.

In this project, I followed the documentation.

After connecting it to a USB port, I installed the fswebcam package:

Using the camera from command line is easy. If the resolution flag isn't specified, the RPI will use a lower resolution: 

The resulting picture has a time stamp in the lower part.

Sometimes, I need to get the pictures to my Windows 10 computer. Since I'm familiar with the scp command, I needed to install it in Microsoft PowerShell:

So far, it is quite straight forward to use Raspberry PI. The earlier models were launched eight years ago, so many of the early bugs and features has been solved over the last years. My board, Raspberry PI 3 B+ was launched three years ago.

The next step will be to setup a web server with a Wordpress web page on the Raspberry PI. I will use that for posting pictures from the web camera. Or maybe I'll just use a Python script for posting the picture on a dedicated blog.


Saturday, 28 November 2020

IOT: Bringing up Raspberry PI

For my IOT project, I'll have a Raspberry PI 3 (RPI) together with some Arduino units, where RPI will serve as a secure gateway to the Internet.

The first step is to bring up the RPI and configure it for a monitor with landscape orientation.

Step 1: Protecting the RPI

Even though some of the circuits are covered, I'm still working with open electronics, that can be damaged just by me touching it. To protect the circuits, I've build a simple box in Lego, where I can still reach the USB and HDMI ports. 

Step 2: Disconnecting the Mouse and Keyboard - Bringing up SSH

I want to use the RPI without keyboard, mouse and monitor. To still be able to control the RPI, I had to install and configure SSH using this instruction.

After a reboot, I discovered that the SSH client (Windows 10/WSL/Ubuntu) timed out when trying to connect to RPI. The SSH client in DOS (Windows 10) worked fine, but I need to understand what happened to the WSL SSH client. 

Step 3: Disconnecting the Monitor - Bringing up Virtual Desktop

It is easy to install the VNC server using apt-get.

Any client will do, I selected RealVNC Viewer.

The desktop is configured for portrait mode.

Step 4: Setting a Static IP address for the RPI

I'm following the guide from raspberrytips.com. The router's IP address is  192.168.X.Y (I won't disclose details regarding my network).

The desired IP address will be 192.168.X.Z and the MAC address is Q. Now, I know enough to set the RPI to have the same IP address. In the file /etc/dhcpcd.conf, I added the following lines:

My typo on the third row disabled internet access to the RPI.
It should be routers.

Finally, I made a reservation for my RPI in my DLink router to ensure that no other device will get the same IP number.
With these changes, the RPI will always get the same IP on this network.

Step 5: Firewall and Antivirus
I'm following the Raspberry PI guide for security.

There is a discussion in the Linux community whether antivirus or firewalls are needed for Linux. Those who say that it isn't needed mean that there are very few viruses targeting Linux. To me, it sounds like "famous last words".

For my system, I personally don't see a great threa.t - I don't save any personal data on my mini computer. I will install it anyways for curiosity. I installed clam antivirus and the iptables/ufw firewall.

I created a new user with root privileges. When trying to ssh to the RPI, I was rejected. I had to add the user to the AllowUsers tag in /etc/ssh/sshd_config file.

Another measure to increase security of the RPI would be to change the SSH port number (default port is 22). Then, an attacker would need to scan the different ports for a SSH connection. Changing port number can be done by editing /etc/ssh/sshd_config.

Conclusion:


Now, the RPI is up and running with an acceptable security. I have a grip on the basics on the Arduino and I've been able to setup a project with a LCD display, several LED's, a potentiometer and a push button. 

The next step will be to connect a 8$ web camera to the Raspberry PI and to set up a web server on that micro computer.

Saturday, 21 November 2020

IOT: Traffic Lights with Arduino - Timer

In the previous blog post, I created a pair of traffic lights. I also added a push button for emergency vehicles that activated a RGB LED that blinked (blue/red).

Now, I'll add a LCD display that will show how long the cars/bicycles need to wait for green light.

The LCD Display

The display that I'll use is a monocromatic display that can show two rows with 16 characters each. It has 16 pins and I'll use 12 of them:

  1. GND - Ground/Cathode. 
  2. VCC -  Anode. Connected to the 5V DC pin on the Arduino Uno board
  3. V0 - Controls the contrast of the display. The user controls the display by turning the knob of the potentiometer that is connected to V0.
  4. RS - Register Set. This pin decides whether to write data to the data register or to the instruction register. 
    1. The contents of the data register goes to the screen. 
    2. The instruction register contains instructions about what to write in the near future.
  5. RW - Select reading or writing mode. I connect it to ground, setting the LCD in permanent writing mode.
  6. E - Enable pin. This pin informs the LCD that it will receive data.
  7. D0 - not used in this case. The LCD can receive the data using either 8 data pins (quicker) or using 4 pins (simpler design). In my case, I'll go for simplicity instead of speed.
  8. D1 - not used.
  9. D2 - not used.
  10. D3 - not used.
  11. D4 - Data pin.
  12. D5 - Data pin.
  13. D6 - Data pin.
  14. D7 - Data pin.
  15. LED+ -  Connected to anode using a 220 ohm resistor.
  16. LED- - Connected to ground.

The Physical Connections

The traffic lights to the left will turn green in 14 seconds.

I had to re-wire the existing LEDs a bit to make the LCD fit to the breadboard. I also ran out of digital pins so I have used three analog pins to power the right set and one analog pin as an input from the push button. 

The Code

I added code for estimating the remaining time until the left and red set of traffic lights turns green. It takes the time in the current state into account and sums up the remaining states until the light turns green.

In case of emergency, the times will temporarily be set to 99 s.

The code is available here.

Next steps:

I'll bring up the Raspberry PI and connect it to the Arduino board. After that,  I want to send some small messages to the LCD on the arduino board.