Showing posts with label PI. Show all posts
Showing posts with label PI. Show all posts

Saturday, April 4, 2015

MQTT - Bridge Work-a-Round

 UPDATE:
I was using a very OLD version of "mosquitto" which did not support Bridges well, I am hoping the current version will work better.

-

To experiment with the Internet-of-Things (IoT), while waiting to receive my Esp8266's (see previous post), I have enlisted my Raspberry PI's into playing the part of a remote data collection device. My Desktop Workstation is the Control Point and the Master MQTT Message Broker.

Originally I had planned to use a Master/Slave Bridged Broker configuration, where the Workstation would be the Master, and the Raspberry PI's would be a Bridged Slave Brokers, and they would collect data and messages from the Esp8266's.

But, I have not been able to get the "mosquitto" Bridged Broker configuration to work as documented :-(

I have a work-a-round; I will temporary use an "ssh tunnel" to directly collect messages from the Raspberry PI's.

At each Raspberry PI's, an "ssh tunnel" is created for "port 1883" (the MQTT port), and therefore the Master Broker is directly available to the Raspberry PI's. A side benefit of is; the "tunnel" is compressed and encrypted.

On Raspberry PI:


$ ssh -CnNTf -L 1883:localhost:1883 <master workstation IPA>




With this setup, I can conduct; tests for camera servo control, send SMS messages to the Cell Phone, and other experiments (see previous posts).



-- Home Page: https://WA0UWH.blogspot.com

Wednesday, April 1, 2015

Sending SMS from the Raspberry PI

Yesterday my friend Larry - KB7KMO was in my Shop, we both have need for Status and/or Alarm Messaging from the Raspberry PI, a casual google searches did not provide much easy help. There is/was much information on how to do it with very long and complex configurations, but we wanted something simple.

After Larry left, and after several hours (actually more than a few) of research, I have found a free service that can be used to send a "SMS" messages from the Raspberry PI to a Cell Phone, using the "curl" command.

Obviously, An Internet connection is needed for the PI, and the "curl" command must be installed (if not already).



$ sudo apt-get install curl



The free SMS service is provided by "textbelt.com" (thanks, textbelt !).

There are limitations to the "textbelt.com" service; no more than 75 messages sent per day from a single IP Address, and no more than 3 messages per 3 minutes can be sent to a single Cell Phone number. For most typical use, this should not be a problem.

Note: the SMS messages received by the Cell Phone will be delivered from "txt@textbelt.com".

Usage: on the command line or shell script:



$ curl http://textbelt.com/text -d "number=AAAPPPNNNN" -d "message=This is a test message"



Where "AAAPPPNNNN" is the: Cell Phone Number, AreaCode, Prefix, and Number. Also, dashes ("-") can be used within the phone number, as: "number=202-555-1212"

Note: the words "number=" and "message=" must be used as shown.

For Canada and International use see: Web page.


- Have Fun with PI Messaging !


-- Home Page: https://WA0UWH.blogspot.com

Tuesday, March 24, 2015

A Lurking Raspberry PI 2

I have been playing with the Raspberry PI 2, connecting a PI Camera and Servos to it. To provide articulation, I used an optional 12" Camera Cable for the connection.

After several hours of research I have figured out how to capture and stream images. Recently I have also figured out how to use the Servos Hat (servo adaptor board) via the Adafruit's I2C Libraries.

So with the combination of Camera and Servos, I now have a "Lurking Raspberry PI".

 I have bits and pieces of programs to control the camera and adjust the servos over the Internet, I just need to assemble the pieces together for a convenient Internet controlled system. Most of the programming will be in python, as contributed libraries are readily available.

The Raspberry PI is currently tethered via a Network Cable, and Power Cord.  But, by adding Wheels, (a big) Battery, and WIFI, is should be able to roam as desired.

My goal is complete control from my Tablet (and from any place on the Internet). Currently, simple Servo Commands can be sent via "ssh" and "telnet" on a private Public IP Address, Private Port, and Private Password. Video is also streamed to a Browser, with and a similar network connection. When completed, a single interactive Web Browser session will control the Camera Servos and future Wheel motors.

One of my goals is to, make the "Lurking Raspberry PI" available to the public with limited control, but that will be in the future.

Raspberry PI 2

I added the Servo Hat, and of course the Adafruit Case was full.

Full Case

Note: it appears that I did not have the Raspberry PI completely snapped in place.

There is not a space to mount the Camera and the Case Lid no longer fit on. So, I cut the bottom out of another one of a Ladyada's cases, which with just a little cutting and adjusting fits perfectly stacked (it almost snaps together). But it may not be an easy task for someone with two left (or right) thumbs. To make things easier, I believe Ladyada is planning an extension case similar to this.

Stacked Cases, The Bottom was Removed from Top Case

The removed (cut out) bottom is being used as an insulator between the Raspberry PI and the Servo Hat, otherwise the Servo through hole pins touch the metal HDMI connector, and it helps stabilize the Hat without special screws and spacers. The Nibs were left on the plastic to help hold-up the far side of the Servo Hat. A slot was cut to accommodate the Camera Cable.

Salvaged Case Bottom

The Two Ganged Servos are mounted on the Case cover.

Servos Mounted

The Case is closed and the Camera is installed, now it is almost ready for Action. The Bands ensure that it does NOT spring apart, and provides anti-skid feet.

Ready For Action
It's Lurking, . . . at me?

It looks like I could have use a little shorter 8" Camera Cable, but 12" Camera Cable will work fine.

More details of this project will follow, I plan to post some photos and/or captured video.

--

Saturday, February 28, 2015

Pi's and Install Configuration

UPDATED:

My Raspberry Pi 2's have arrived!  Two of which are now running on the Internet.  I have three locations that I want to install and run them from.

New Raspberry Pi 2's
The initial installations will be running Raspbian (wheezy) serving simple Ham Radio Blog pages and running some HF Beaconing or Receiver code. See: http://dc01.ebcon.com:8040/

As a system administrator for large employers, I have installed and configured many Linux (UNIX) systems, I now have it down to quick trivial process.

For Raspberry Pi, First:

On the Raspberry Pi, I immediately execute the following commands:




$ sudo aptitude install ssh sshuttle
$ sudo aptitude install xosview htop tree wicd apache2 php5
$ sudo aptitude install vnc-server vnc-viewer




Note: if these are already installed, no harm. See the man pages as necessary.

Then I add users as necessary, with:



$ sudo adduser <user_name>




And then, add the appropriate admin "user_name" to the "sudo" group


$ sudo adduser <user_name> sudo




Then:

There are several things I DO NOT like about most default UNIX installations.

The first is the default command "prompt", which is typically a long string of characters that is; the user and system name, and the current working directory. The information is good, but the format is terrible. While in a directory way down in the directory structure, typing space on the displayed command line is very limited, and wraps around and is difficult to use. For example, change to the directory as shown:



$ cd /usr/share/SuperCollider/SCClassLibrary/Common/GUI/PlusGUI/Control/



This will result in a Command Prompt of:



pi@rbpi3 /usr/share/SuperCollider/SCClassLibrary/Common/GUI/PlusGUI/Control $ 




Note: there is little typing space on the line to the right of the "$". There is little wonder why most users get turned OFF with the Linux Command Line environment.

I personally like the same information, only in a different prompt format. For example (see below), the "date" command was entered at the prompt, and then executed, a new prompted followed:




/usr/share/SuperCollider/SCClassLibrary/Common/GUI/PlusGUI/Control
rbpi3$ date
Sat Feb 28 12:32:40 PST 2015

/usr/share/SuperCollider/SCClassLibrary/Common/GUI/PlusGUI/Control
rbpi3$




In this example the prompt starts with a blank line, followed by the current directory, and then on the next line, the name of the system, followed by the "$" prompt. Regardless of the length of the current directory, the user starts typing at the same location on the command line (and with space to spare).

Modifying or Adding this type of Prompt is simple, but I have done it "too" many times, see shell script below.



PS1='\n$PWD\n\h\$ '



Also, I set the default "command line editor" to "vi", this allows the use of "vi" key commands to "edit the command line", and access "command history stack". As in; "h" and "l" (cursor Hop-left and Leap-right), "j" and "k" (history Jump-down and Klimb-up). Also, see shell script below.



set -o vi



I now add a simple script (/etc/bash.bashrc.local) to each system I install. It contains all of my favourite system modifications. The script is as shown below, details are not provided, but maybe you will find bits-of-it you would like also.

Note, depending on the initial OS installation, each user may want to remove the ".bashrc" and ".profile" from their home directory, or adopt parts of this script in their files. I like the system wide approach, an yet, while knowing that it is a little dictatorial.




#
# Usage in /etc/bash.bashrc
# Add the following two lines to the end of /etc/bash.bashrc, uncommenting the "test" line.

   # Start up /etc/bash_localrc for Local Stuff
   # test -f /etc/bash.bashrc.local && . /etc/bash.bashrc.local

# Local Startup files for Bash

   #echo "Start: /etc/bash.bashrc.local"
   #set -xv

   TZ='PST8PDT'; export TZ
   PATH=/usr/local/lbin:$PATH

# Show System Key

   # KEY="$(ssh-keygen -l -f /etc/ssh/ssh_host_rsa_key.pub)"
   # KEY="${KEY#* }"
   # echo
   # echo "System Key: ${KEY% *}"

# Setup the default editor
   export EDITOR='vi'
   set -o "$EDITOR"

# Setup History
   HISTSIZE=10000
   HISTCONTROL=ignoreboth:erasedups
   shopt -s cmdhist histappend lithist execfail

# Add extended globing
   shopt -s extglob

# Set the Terminal Tab value
   # If this is an xterm set the title to user@host:dir
   case "$TERM" in
   xterm*|rxvt*)
    PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}\007"'
     ;;
   esac

# Prompt # for root, $ otherwise
   PS1='\n$PWD\n\h\$ '


# Local Aliases
   alias ll='ls -l '
   alias bdf='df '
   alias is='ps -ef | grep -v grep | grep -- '

   #set +xv
   #echo "End: /etc/bash.bashrc.local"


# Some Interesting Shell Stuff
   alias ralias='. $HOME/.alias'; # reread HOME aliases
   alias ...='cd ../..'
   alias ..='cd ..'

# Local GitHUB Aliases
# Git related
   alias gco='git checkout'
   alias gci='git commit'
   alias gst='git status'
   alias gbr='git branch'
   alias gls='gbr'
   alias gsbr='git show-branch'
   alias gmg='git merge --no-ff -v --progress'

   alias gad='git add'
   alias gdf='git diff'
   alias glg='git log'
   alias ggp='git grep'
   alias gpu='git push'
 
   alias gk='gitk --all &'
   alias gr='git rebase'
   alias gri='git rebase --interactive'
   alias gcp='git cherry-pick'
   #alias grm='git rm'

# End



I use "scp" to grab the script from a previously installed system.


Security Tip

If you going to put a Raspberry Pi on the Internet:
  • Remember to set a new passwd on the pi login
  • Do not open the ssh port 22 directly to the Internet, use a router to NAT and route another port to the Raspberry Pi. Note: if you DO open port 22, your system will be hammered by break-in attempts. Check your logs often.
  • Open only the ports that are necessary for your applications.
  • Also, I recommend doing something similar for port 80.

Be careful, the Internet is full of malicious hackers and "script kiddies" that will take over and eat your Raspberry Pi.

The following is a script that I wrote many years ago, as "taillogs", it "lists" and "follows" the system logs, showing new log events as they occur. I know it is somewhat cryptic, but does a nice job.

I saved this in a file: "/usr/local/lbin/taillogs".

Note: "/usr/local/lbin" is where I save all of my authored scripts.




#! /bin/sh
# Author: Eldon R. Brown, eldonb@ebcon.com

        cd /var/log &&
        find . -type f -print |
        egrep -v "\.[0-9][0-9]*$|OLD|mbox|\.offset$" |
        xargs ls -tr |
        xargs file |
        sed -n '/ text/s/:.*//p' |
        xargs tail -n2 -f

# End



With this script, it is easy to check your system logs.


-- Home Page: https://WA0UWH.blogspot.com

Thursday, March 14, 2013

National Pi Day

Today, Mar 14, 2013 is National PI day.

When written as numeric today's date is 3/14, is similar to 3.14, which of course is the value of the first three digits of PI.

PI Day should be celebrated at 6:28 am, as that is the value of  "Tau", which is the value of  2xPI.

Today is also Albert Einstein's Birthday Anniversary (Mar 14, 1879) - PI Day is a well fitting tribute to a great man.

--

Thursday, February 28, 2013

Rpi on the Network

As mentioned in the previous post, I now have my Raspberry PI (Rpi) connected to the Network, serving Web Pages and providing (my) access via SSH and Remote Desktop.

Only one wire is needed for this configuration, that is the 5 Volt power from a 1 Amp wall wart. Network access is via the USB WiFi Adapter as shown in the photo. This Rpi can be accessed from anywhere in the world as http://Rpi.WA0UWH.com:8040 . Currently it is serving only a single web page, other fun pages (or links) will be added later.
Rpi running a Web Server, SSH, and Remote Desktop
http://Rpi.WA0UWH.com:8040
My plans include connecting the Rpi to an Ensemble Receiver (SDR), which can be done with only the addition of an Antenna and USB Sound Card.

I am considering moving the Rpi and the SDR to a remote location (where I have WiFi access) so that I can Transmit from my Shack, without overloading the SDR. This remote location will be good for remote QRSS Grabber operation.

I am impressed with the Rpi, it is a fun system.


-

Thursday, February 21, 2013

A Piece of the PI

Several days ago, I received an e-mail from Adafruit informing that they had Raspberry PI boards available, I had been on their waiting list for several weeks. Once ordered it was only a few days before the PI arrived - yesterday.

I spent several hours reading the "Getting Started" web information pages. I did not purchase a pre-loaded SD card as I have several.

Some Lessons learned
  • The micro USB connector is only used for power (+5V).
  • It is difficult to use the PI if you do not have a HDMI display, but it is possible to run the PI without a display, but when first starting and not knowing what to expect, it was difficult to know that it was actually working (or NOT). Now I know that the 5 LEDs blink and flash when booting. Initially I had a bad SD card and nothing was working. A working PI boots in about 30 seconds with all LEDs flashing.
  • Thanks to information found on the web, a static address can be forced (for easy access via SSH), by editing the "/etc/network/interfaces" while the SD card is mounted on another system, I used 192.168.2.40
Orignial file: /etc/network/interfaces

auto lo

iface lo inet loopback

iface eth0 inet dhcp

allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp


File changed to:

auto lo

iface lo inet loopback

#iface eth0 inet dhcp

auto eth0
iface eth0 inet static
address 192.168.2.40
netmask 255.255.255.0
gateway 192.168.2.1
dns-nameservers 192.168.2.1

allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp


Soon, I will replace the Ethernet cable with a WI-FI adapter, and replace the Micro USB +5V supply connection with a battery. I will then have a stand-alone portable networked system. I will probable only use SSH, VNC, and remote X11 windows to access the PI.

I think I will like the PI, it boots fast and with an USB audio adapter it will be useful for my Ham Radio adventures with SDR and other radio controls.


UPDATE - Feb 21, 2013
With the following command, I installed "fldigi"
  • aptitude install fldigi
I do not have a USB sound adapter installed yet, but "fldigi" runs with my minimal configuration!

I need to get a stand-alone USB wall wart to power the PI (or a battery) and a USB expander to connect other USB devices (i.e., sound adapter), the PI has only a minimal amount of current it can supply to external USB devices. Other web doc's suggests a powered USB Expander is required.


UPDATE - Feb 22, 2013
I returned the "/etc/network/interfaces" file to original configuration, and then modified my home router config to serve my desired IP Address for the PI's MAC address via DHCP. The advantage here is the PI will have a known IP Address while on my Network, but will obtain any an available DHCP IP Address when at any other location.


UPDATE - Feb 25, 2013
I now have the PI serving web pages, as: http://Rpi.WA0UWH.com:8040


UPDATE - Feb 27, 2013
My PI is now using an WiFi connection to the network, only the single power connection wire is connected to the PI. The power cord could be replaced with a Battery for a completely portable PI web server.

I used information found at: http://www.raspberrypi.org/phpBB3/viewtopic.php?f=26&t=26795. The only difference is that I set up to use a Static IP Address as configured and served via DHCP from my WiFi Router.


UPDATE - Mar 10, 2013

Sometime today my Rpi died, not sure why, but I will not have time to fix/rebuild it until later this week. At last count it had served a connection for 213 users via web requests.

--