Friday, April 27, 2018

Installing software onto the Raspberry Pi- Part 2

Finally here's where we install the Linux software for monitoring the Smart Meter!
Based on the previous work done for the testing on a Windows PC, we are going to need:
  • rtl-sdr drivers
  • rtl-tcp server
  • rtlamr decoder
But instead of Windows sources, we are going to need the ones for Raspbian.

RTL-SDR / RTL-TCP

The following post was extremely helpful in setting up the rtlsdr software on the RPi:

  • First we need to install some packages required by the rtl-sdr dongle server:
  • Instead of going to the NooElec website for pre-compiled Windows drivers, we will get the sources from:

    Fortunately 'git' is already included with the installed OS, so we can execute the following directly in /home/pi to get the rtl-sdr code:
(Note that in order for certificates to work for https access, you must have your OS set to the correct date and time !!
  • We can now run the following (note it may take some time to complete):
  • Before we can install the rtl-sdr USB dongle, we need to setup a 'blacklist' file to prevent the standard USB Radio/TV drivers from loading. Create the file 
/etc/modprobe.d/blacklist-rtl.conf
         
         and add the following lines to it: 
  • You can now reboot the RPi, install the rtl-sdr dongle, and run rtl_test  
(use Ctrl+C to exit the test):

RTLAMR

  • Before we can download and build rtlamr, we need to install the go build environment


(since this is for the RPi, we will need to get the version that runs on the ARM processor;  
as of this posting, the latest go release is 1.10):

  • If all has run successfully, you can now check the go version:
  • We can now download and build bemasher's rtlamr from
https://github.com/bemasher/rtlamr

  • You can now start up rtl_tcp in a terminal session:
  • And then start up rtlamr in a different terminal:
Next steps:
  • Configuring the meter reader software

Thursday, April 26, 2018

Installing software onto the Raspberry Pi- Part 1

Now that the Raspberry Pi can access the internet, we can begin adding and configuring software.
One of the first things to do is log into the the RPi via SSH and run raspi-config:

We will:
  • Update raspi-config
  • Set Localization options
    • Change Locale to 'en_US.UTF-8 UTF-8'
    • Change Timezone to US-Eastern
    • Change Keyboard Layout to match the new locale
    • Change Wi-fi Country to 'US United States'
  • Under Advanced Options
    •  Expand Filesystem to use the entire microSD card
Now that we have plenty of space on the system disk, we can start installing software.
But how? Some options:
  • From the RPi SSH terminal command line
  • By downloading software packages onto the laptop and transferring them to the RPi for installation (WinSCP is good for this):
  • Installing via the Rasperry Pi Desktop's Applications Menu -> Preferences -> Add/Remove Software.
    • But we are running headless and there's no Desktop GUI!
While the first two options can be followed immediately, let's figure out how to get access to the RPi  Desktop. We want to use VNC (Virtual Network Computing) for graphical desktop sharing:


On your Raspberry Pi, run the following commands to make sure you have the latest versions of software, including VNC Connect:


Now, enable VNC Server by running raspi-config and doing the following:
  • Navigate to Interfacing Options.
  • Scroll down and select VNC > Yes.

On the laptop you will need to download and install VNC Viewer so you can connect to VNC Server that is running on the RPi:


Once it is installed, we can start VNC Viewer on the laptop, direct it to the IP address of the RPi and login with our default credentials:

 And we are in!:


Next steps: 

Wednesday, April 25, 2018

Sharing your laptop's internet connection with your Raspberry Pi


In the previous post, we set up a headless Raspberry Pi and connected to it via a PuTTY SSH terminal session running over the local NIC. In order to update and install software onto the RPi, we will need to give it access to the Internet and all of its code respositories. For example, you will need this when you run 'sudo raspi-config' and need to select Option 8 to update to the latest script version:


Since it is the Windows laptop that has access to the global network, we will enable Internet Connection Sharing between the global interface and the local NIC so the RPi can route through the laptop to the web. I found a couple of references on how to do this, but encountered differences in behavior on Windows 7 and Windows 10.

https://raspberrypi.stackexchange.com/questions/23627/how-to-share-my-internet-connection-on-a-windows-computer-with-a-raspberry-pi

https://raspberrypi.stackexchange.com/questions/63153/connect-pi-to-windows-10-with-internet-connection-sharing 

 To get it working on the Windows 10 laptop:
  • Go to the NIC that is connected to the outside world (in my case, this was my laptop's WiFi adapter) and enable Internet Connection Sharing:
  • When ICS is enabled, the wired NIC will automatically be assigned an IP address of '192.168.137.1' with subnet '255.255.255.0'.
  • Use PuTTY to login to the RPi at the IP address you found using Wireshark and edit the file /etc/dhcpcd.conf  to set a new static IP address and DNS server:
interface eth0
static ip_address=192.168.137.2
static routers=192.168.137.1
static domain_name_servers=192.168.137.1 8.8.8.8
  • Reboot the RPi and login over SSH again using the new static IP address (192.168.137.2). You should be able to run 'sudo apt-get update' to download RPi updates from the global repository:

    
    
Next steps:

Tuesday, April 24, 2018

Setting up a headless Raspberry Pi

At the end of my previous post on reading my Smart Meter, I said I wanted to move the monitoring hardware and software off of the PC and onto a dedicated Raspberry Pi. Since I wasn't getting to this task at home, I thought I would try to do it during lunch at the office. Unfortunately, I don't have access to as much equipment there, but then that's part of the challenge.

In the office I just have my laptop, with keyboard and monitors tethered to other systems.  I was planning on following the steps in this post on configuring the RPi without those devices, and only using a PuTTY SSH to establish a serial terminal connection:


However, I also do not have open access to the corporate network or router and am running Windows instead of Linux. There were some more tips here for a direct ethernet cable connection:


but the problem is I do not have a good way to determine the IP address that the RPi self-assigns when it boots. Then I remembered that I run the Wireshark protocol analyzer on my Linux systems, and there is also a Windows version available!


So here's the steps:
  • On the Windows laptop, download the latest version of Raspian and burn the image to a microSD card.
  • From a Windows command prompt, create a dummy file named 'ssh' and place it in the Linux boot directory located on the card (in this case, the card reader has assigned drive E to it).
    • copy /b NUL ssh
    • move ssh e:
  • Eject the the microSD card and install it into the RPi.
  • Connect the laptop and the RPi together with a standard ethernet cable.
  • Power up the RPi and wait a couple of minutes for it to self-assign an IP address.
  • On your laptop, start Wireshark and select the Ethernet interface to analyze:


  • Examine the first few lines of the analysis to see what IP address the RPi is broadcasting from (in this case 169.254.12.109):

  • Now that I know the IP address, I can log into the RPi using PuTTY:

  • And we are in!!

    Next steps:
    •  Configure the RPi's network settings (e.g., set a static IP address)
    •  Set up internet connection sharing on my laptop so I can update the RPi with the RTLSDR software: