Skip navigation
2016

OVERVIEW

In this article we'll show how to control your Raspberry Pi terminal from Facebook.

Result

 

Below is a block diagram illustrating how we set up a web application running on a Raspberry Pi, made available to a Facebook application webhook via dataplicity Wormhole.

block diagram

PREREQUISITES

You will need:


CREATE A FACEBOOK ACCOUNT

This will be the administrator account for the application that we'll implement in the next steps. If you would like to use your own account or already have a separate account then you can skip this step.

To register simply fill in the registration page with your details.

1


CREATE A FACEBOOK PAGE

A Facebook "Page" is not the same as your personal Facebook timeline - it's a page normally created to represent a group, company, or other more organised presence on Facebook. This will be the front end for our application.


To create a page click on "Create Page" in Pages section in the menu on the left.

 

2

 

In the next window you'll be asked what type of page you would like to create. Choose Brand or Product.

 

3

 

When you click on Get started you will be asked to fill in some info about the page. You can either fill it in or skip most of it.

 

4

 

CREATE A FACEBOOK APP AND SET UP A WEBHOOK

Go to https://developers.facebook.com/ and log in using the administrator account you created in the first step of this article.

 

Click on My apps field beside your thumbnail in the top right corner. This will direct you to the page containing your apps. Click on the green button Create a new app. Following that a window will pop up asking to fill in some details. Fill all the details and click on Create App ID.

5

 

On the next page click on + Add Product in the menu on the left. Click on Get Started with Webhooks then go back to a previous page and do the same for Messanger.


As you click on get started with Webhooks you will be asked to add a new subscription on the next page.

 

6


DOWNLOAD THE CODE

The Raspberry Pi code is available on github.

 

To download it onto your Pi please use the command below:

wget https://github.com/wildfoundry/specialprojects-public/archive/fbpi.zip 

followed by:

unzip fbpi.zip 

To unpack the code from zip archive.

It is important to download the code at this step in the article because the next steps require a few minor modifications to parts of this code.

SET UP THE SERVER

After unpacking the code files please open your terminal emulator in the same folder. Run the server using command below.

sudo python server.py TermPassword

TermPassword - This is the password we use to prevent other people on Facebook from controlling your Pi. You will need it when you start terminal mode inside the Facebook chat window. We recommend you pick your own password instead of the one we use in this example.


At this point it is important that you already have dataplicity installed on your device and Wormhole enabled. See Getting Started with Dataplicity for help to get to this point.


When you run the server, you should get a message indicating that the server is starting and then that it's running. To check that it's working correctly please go to your wormhole address inside the browser and you should see "Hello world".

7

 

This indicates that the server is functioning correctly. You can stop the server for now by pressing CTRL + C. The next step is to edit facebook.py file. Open it with your favourite editor such as nano.

nano facebook.py

Inside that file modify the SUBSCRIPTION_TOKEN variable at the top by setting it to any string you want. We'll set it to:

SUBSCRIPTION_TOKEN = "tok_dp_fb_term"

save the file and close it. Run the server again.

SUBSCRIBE YOUR WEBHOOK TO THE SERVER

Return to your Facebook Developer page, and in the menu on the left side go to PRODUCTS section and click on Webhooks. Click the green button in top right corner that says New Subscription and from the drop-down menu select page. Next a form will pop up - fill it in as follows:

Callback URL:

https://<YOUR_WORMHOLE_ID>.dataplicity.io 

(Change <YOUR_WORMHOLE_ID> to match your device's Wormhole address)


Verify token:

tok_dp_fb_term 

(Note that this must match your SUBSCRIPTION_TOKEN inside the facebook.py)


Subscription fields:

messages 

8

 

Click on Verify and Save. On the terminal emulator you should see your server receive a GET request. If everything was done correctly you should now see the following subscription on your developers page:

9

 

GET STARTED WITH FACEBOOK MESSENGER

Back in your Facebook Developers console, go to PRODUCTS section and click on Messanger. Click the blue Get Started button.

You will now see a couple of sections on the next page. The ones that we're interested in are Token Generation and Webhooks.

 

In Token Generation sections click on Select a page button and from the drop-down menu select your page. You will get a pop up window asking for permissions and whether you want to continue as current user. Click on OK for everything.

 

In Webhooks sections click on Select a page button and from the drop-down menu select your page and click the blue Subscribe button.

 

11

 

Copy the Page Access Token.

 

You can stop the server for now by pressing CTRL + C. The next step is to edit facebook.py file. Open it with your favourite editor (e.g. nano).

nano facebook.py

Change the ACCESS_TOKEN variable at the top of this file to the string you have just copied from Page Access Token field on Facebook.

ACCESS_TOKEN = "EAAI3ZCiMmzZAI ... hWN0vnDyUkqrL6XQ1u9 ... VvQgm0"

save the file and close it.

 

Run the server again and proceed to the next step.

sudo python server.py TermPassword 


MAKE YOUR APPLICATION PUBLIC

Return to the Facebook Developers site, and in the menu on the left side go to App review section. 

Click on the sliding button to make the app public. After you do this, you will be able to send messages to your Facebook Page (ie Raspberry Pi) from accounts other than the administrator account.

12

RUN IT!

Try sending some messages to your Pi from the Facebook page you have created! Let's send a help command to see other commands that we can use in our messages.

12_v3

 

Other than help we have 3 other commands available:

  • date - Returns current date on your Raspberry Pi.
  • time - Returns current time on your Raspberry Pi.
  • term <password> - Enters into terminal mode. ( The date and time commands above are used in normal mode. )


Below is an example of a response to running date and time commands. We can also see that in normal mode when you send a command that's not recognized it will be echoed back with appropriate response.

date, time unknown

 

The terminal is started by sending:

term TermPassword 

(replace TermPassword with the password you set when you started the server on your Pi

 

It then enters into the terminal mode that starts a shell on the Raspberry Pi and runs it until exit command is received. The exit command is part of the shell rather than our program, hence it's not on the above list of commands.

 

Run your Terminal:

14

A WORD ON SECURITY

Please note the security of your Pi terminal in this project is down to the complexity of the password you choose. It is also a project we just built for fun and almost certainly has bugs so please use with caution.


If you find any issues please comment them here or if you want you can contribute to our github. Any further suggestions how to improve this project will be much appreciated.

EXPANDING THE PROJECT

There are lots of things we could add at this point:

  • Create a GPIO Mode to switch on/off GPIO pins and switch on/off LEDs
  • Use Facebook Messenger to send files directly to the Pi
  • Add some AI to the chat while in normal mode.

I found this distribution to be the simplest to install, localize, and set-up networking for (wired or WiFi, static IP or DHCP).  I was impressed enough that it is on all of my computers:

  • RPi2 (ARMv7) SoC
  • Pine64+/2GB (64-bit ARMv8, like RPi3) SoC
  • Biostar NM70I-1037U (Dual-core 1.8GHz x64 Celeron) motherboard
  • Zotac IONITX-FE (Dual-core x64Atom 1.6GHz) motherboard

 

I am using version 16.04.  The only major flaw (WiFi not processed during installation, https://bugs.launchpad.net/ubuntu/+source/network-manager/+bug/1572956 ) that I found is easily worked-around by an extra reboot following the first boot after installation.  This is supposed to be fixed in the next release, version 16.10.  More about WiFi later.

 

Download and get post-installation instructions from here: https://ubuntu-mate.org/raspberry-pi/

 

Keep in mind that the download thingie is not a ZIP file but a WZ file which contains the IMG file.  In Unix and Linux, you can obtain the IMG file with the `unxz` utility (Debian/Ubunut/Mint: sudo apt-get install xz-utils).  Mac probably performs GUI magic.

 

Boot up of the MicroSD the first time, gets you here (pardon my photography):

First screen following boot

After selecting English, they asked me where I was:

Where are you?

Next, I was prompted for my keyboard layout:

Keyboard layout

Next, who are you, your computer name, and do you want to auto-login?

Who are you?

That's it!  No more data entry screens for installation.  Commercials during installation:

Commercials

After the first boot, you get the desktop plus a welcome pop-up:

Welcome

Click on the red rectangle (Raspberry Pi Information) and select Resizing the File System (sorry, I neglected to catch it before I completed it):

Resize the file system

I probably was told to reboot too (after resizing) but I forgot!  Here is the layout of the Mate Control Center:

Mate Control Center

I normally just use wired-Ethernet but since I do have an EDUP USB WiFi dongle, I'll demonstrate configuring both.

 

Included in Mate is the Network Manager GUI which obviates the need to edit system configuration files directly.  Network Manager has evolved successfully from SysV to Upstart to Systemd service managers.  Ubuntu Mate, like the rest of the Ubuntu family is using Systemd as of 2016 for releases.  But, if you use the Network Manager GUI, you won't be required to know, in advance, what methodologies and which folder locations for the network details of your service architecture.  Of course, you can find this out if you are curious.

 

So, look up to the right-hand side of the top panel ("Panel 0") and you should see one arrow pointing up on left and its twin pointing down.  Click once on it and you should see something that will eventually look like this:

 

Network Manager drop-down menu

The above picture reflects auto-configuring wired and having completed the WiFi work-around reboot which will be unnecessary in version 16.10.  You can see that there is a "Wired connection 1" (name will change automatically) under "Ethernet Network" and a list of two possible WiFi routers I could try connecting to.  I'll set up WiFi first.

 

It so happens that NETBEAR is mine and 2WIRE007 must be one of my neighbors so I did the following:

  • Clicked on NETBEAR
  • Entered the password
  • Clicked on "Connect" to complete the connection.  The cryptographic methodology is negotiated transparently although you could try to edit it subsequently.

 

I decided for this WiFi connection, I'll leave it as DHCP (the default for all connections) but I really want a fixed IP address for the wired connection.  Note the following picture:

Connections completed

To edit the wired connection, I clicked on "Edit connections ..." in the Network Manager drop-down menu which got me the "Network Connection" box in the upper left of the picture.  I highlighted the wired name (shown there) and clicked on "Edit".  Note that the wired name changed.  It now has a name governed by the "Predictable Network Interface Names" scheme (https://www.freedesktop.org/wiki/Software/systemd/PredictableNetworkInterfaceNames/ ).  I wish that had happened from the get-go and I never saw the "Wired connection 1" label.  Well, nobody is perfect.  I hope that this does not confuse a novice.  Never edit "Wired connection 1".

 

In the lower left of the picture, you should find an "Editing ..." box with details that I entered for my wired static address:

  • Method: Manual
  • Addresses (only one)
    • Address 192.168.1.103
    • Netmask 24 (I could have entered the equivalent 255.255.255.0)
    • Gateway 192.168.1.1 (My router's IP address)
  • DNS servers (only one): 192.168.1.1 (My router = my DNS server)

 

and then I clicked on "Save".

 

Note that the Addresses component entry process is a bit brittle and has been complained about.  Enter the components this way:

  • Pi Address value
  • Press the Enter key
  • 24 (or whatever your netmask value should be)
  • Press the Enter key
  • Gateway address value
  • Press the Enter key

Do not use arrow keys.  If something goes wrong, start over.  I agree that brittleness has no excuses.

 

The result is the lower right hand box showing the NETBEAR tab and the `ifconfig` output in a terminal window behind the 3 boxes.  You should see that the wired connection has a static IP address and the WiFi connection is using the DHCP scheme.

 

That's it.  Not perfect but quite simple, quick, and has network configuration heading in a productive direction.

 

Comments?  Any interest?

This is a much-needed update to the blog entry that I wrote in April 2015 with respect to RPi2 and was last updated this past September.  Much thanks for comments by clem57 , anthonyworth , and sergiokob (RPi3 comments).

Why a static IP address for the Pi?  Well, you might not want it to change so that you can use a Pi in the following example repeated situations:

  • sshd (allow ssh clients to connect for various reasons)
  • rsync (copy from/to over SSH)
  • remmina (remote desktop server)
  • Samba (Windows file server emulation)
  • FTP

 

Keep in mind that a router would vary non-static dynamic address periodically during an automatic address renewal or after a Pi reboot (which usually causes a DHCP renewal).  So fixing the address of a set of common services is desirable.

 

Some administrative specifics about my LAN (router environment) to explain the addresses which appear later:

  • Router and DNS (combined in my router): 192.168.1.1
  • Dynamic address range: 192.168.1.{201, ..., 299}
  • Static (manual-assignment) address range: 192.168.1.{101, ..., 199}

 

The /etc/hosts file on one of my machines (biostar) contains the following static-address entries:

127.0.0.1    localhost

127.0.1.1    biostar

192.168.1.1     router

192.168.1.101    zotac

192.168.1.102    biostar

192.168.1.103    raspbian

192.168.1.104    pine64

 

The RPi2 file /etc/network/interfaces as installed today:

 

source-directory /etc/network/interfaces.d

 

auto lo

iface lo inet loopback

 

iface eth0 inet manual

 

allow-hotplug wlan0

iface wlan0 inet manual

    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

 

allow-hotplug wlan1

iface wlan1 inet manual

    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

 

So, it is not surprising that my Pi, according to `ifconfig`, was running eth0 at "inet addr" 192.168.1.235.

 

For the long-term, I want to fix my RPi2 using wired-Ethernet at 192.168.1.103.

For a WiFi test (EDUP USB/WiFi adapter), I will create a temporary WiFi static connection at 192.168.1.199.

 

It's most unfortunate that Raspbian-Jessie still does not include one of the network-manager GUIs found in many of the other LightDM-based distributions; this would have made this job simpler and not required manually editing of system configuration file(s).  On the other hand, this is an educational opportunity.

 

Keep in mind that the below-defined recipe may not work in future Raspbian releases.  For example, when I upgraded the "biostar" desktop Xubuntu image during 2015, I noticed that the network configuration strategy switched when migrating from the Ubuntu "upstart" service manager to the "systemd" service manager.  Surprise, surprise.  I had already gone through this once before from "SysV" to "upstart".  This is why Network Manage GUIs are so helpful and time-conserving.

 

Back to the task at hand - I followed this recipe today after a re-installation on my RPi2:

  • I left /etc/network/interfaces alone (Thank you, Sergio).  The 2015 strategy (SysV-oriented) of editing /etc/network/interfaces directly failed to work again in 2016.
  • I appended /etc/dhcpcd.conf with the following static information without the parenthetical comments:

interface eth0 (Wired-ethernet)

ipv4only (only using IPv4)

static ip_address=192.168.1.103 (following my /etc/hosts plan)

static routers=192.168.1.1 (my gateway address)

static domain_name_servers=192.168.1.1 (my router provides my DNS service which is fast enough for me)

interface wlan0 (WiFi)

ipv4only

static ip_address=192.168.1.199

static routers=192.168.1.1

static domain_name_servers=192.168.1.1

  • I appended /etc/wpa_supplicant/wpa_supplicant.conf with the following static information without the parenthetical comments:

network={

               ssid="It's-a-secret"

               psk="It's-a-secret"

}

  • Reboot

 

Sergio (mentioned above) put his wlan0 static IP address in the /etc/wpa_supplicant/wpa_supplicant.conf file.  It can, apparently, go in either file.  I'll guess that he did this because he only wanted to modify one file since he had no wired-Ethernet connection to configure.

 

NOTE that if you create two connections to the same host, ssh client will not be happy with trying to switch from one to another - "Host key verification failed".  Work-around for me:

ssh-keygen -f "/home/elkins/.ssh/known_hosts" -R 192.168.1.103

Start over (`ssh 192.168.1.103`)

 

Since this recipe worked on RPi2 and RPi3 before, I assumed that the RPi3 would still work with the above recipe (I don't have one to test with).  Any RPi3 assistance will be appreciated.  I will correct as necessary.

boinc_mgr_tasks.jpgboinc_params.jpgtop.jpg

 

This is a much-needed update to the blog entry that I wrote in May 2015.  Thanks to subsequent comments by Daniel Carrion (off, busy on other things now), Jose Berrios, kiltedken , suprimex , dirkbroer , and mchuntley.

 

In September 2016, the current Raspbian boinc-* packages will, indeed, get you a working boinc project on the Raspberry Pi 2 - just avoid installing the boinc-app-seti package from Jessie.  Yes, this blog entry is smaller because one year's progress has shortened the lengthy previous procedure required for the Raspberry Pi 2.

 

Recipe follows:

 

1. sudo apt install synaptic

     (great package manager if you have not already installed it)

 

2. Launch synaptic (enter the sudo password).

 

3. Synaptic: Search for "boinc"

 

4. Synaptic: Select boinc-manager

     (implies boinc-client and other dependencies)

 

     Note that boinc-app-seti (SETI@Home v7) in the Jessie repo is out of date and needs an update

     to v8.  This has already been reported.  I suggest adding SETI@Home when you first

     launch boinc-manager; this will automatically get you SETI@Home v8.

 

     Note that you can get many available boinc apps through the use of

     the boinc-manager (GUI) or boinc command line (`boinccmd`).

 

     I did not install the graphics because (1) more resources would be eaten up on RPi

     and (2) I'd rather do my own mathematical plotting.

 

5. Synaptic: Apply

 

6. Exit synaptic

 

7. On the menu bar, Applications > System Tools > BOINC Manager

 

     The initial red flashing notices is *NOT* an alarm but worth reading.

     In the future, this might indicate something worrying about.

 

8. Add project (SETI@Home) or any other project that appeals to you.  Sign-up or Login.

 

9. My personal preference: change View from Simple to Advanced.

 

Pictures at the beginning of this article:

 

  • Boinc Manager task tab showing 2 assigned Seti@Home assignments running at 100% of a CPU core each.
  • Boinc compute preferences.  If you notice pi-sluggishness in the future, you might want to un-check the "While computer is in use" box.  I do not believe that there exists yet any Raspberry Pi GPU support.  Maybe in the future.
  • Watching the boinc-client processes with `top`.

 

Any other Boinc users here at Element 14?

 

This video is all about connecting MCP3208 with Raspberry Pi and accessing it using JAVA.

----------------------------------------------------------------------

Repository : https://goo.gl/7NRe5n

Schematic : https://goo.gl/kbkhj4

Code : https://goo.gl/J0BT8p

Compiled JAVA App: https://goo.gl/pvb6Sp

Lib :  https://goo.gl/NyI9vL

 

----------------------------------------------------------------------

Subscribe : http://goo.gl/gM134X

 

Guys Subscribe to my channel for latest contents into your inbox. Support me to keep going.

-----------------------------------------------------------------------

Blog :http://goo.gl/8BTy4z

Twitter : http://goo.gl/1UVHjG

GIT: https://goo.gl/L71Oct

Raspberry Pi 3

 

This week, the Raspberry Pi foundation celebrates another milestone with the announcement that they have sold over 10 million Raspberry Pi's around the world.

 

As a leading distributor and manufacturer of the boards, Premier Farnell has manufactured and sold almost seven million devices, not to mention millions of accessories and related products. Our element14 community has also become one of the leading platforms for Raspberry Pi enthusiasts, with thousands of members sharing their projects, insights and design ideas with fellow makers around the world.

 

In honour of ten million global Raspberry Pi sales, we're shining a light on ten of the best and most innovative Raspberry Pi member projects to have appeared here on the element14 Community to date.

 

Meditech by balearicdynamics

 

Meditech

 

The winner of our 'Sci Fi Your Pi' design challenge, Meditech incorporated the Raspberry Pi into a Star Trek-inspired portable examination kit that can measure heart rate, body temperature, blood pressure and blood glucose, in addition to assessing eye health and conducting body surface image analysis.

 

Read our interview with Meditech creator Enrico Miglino

 

CaTS by fvan

 

 

 

For our Forget Me Not design challenge, we asked our members to deliver an IoT solution that would improve the user's peace of mind while they were on a vacation holiday. Frederick Vandenbosch's winning entry was a system for monitoring and automating a variety of household appliances, in addition to tracking and feeding household cats. Frederick built his system around a Raspberry Pi Model B+, using its GPIO pins and USB ports to connect a variety of sensors. In addition, he used the RPISoC for tasks such as driving servos to control the automatic dispensing of cat food, and an EnOcean PI to monitor remote conditions such as whether a door was left open or closed.

 

Read the project summary

 

Offline Karaoke Maker by indiant3chi3

 

 

The winner of our Rocking Raspberry Pi challenge, Shrenik Shikhare combined the Raspberry Pi with a Wolfson Audio Card to create an 'instant' Karaoke machine that provided excellent sound quality and could be used anytime, anywhere without connecting to the internet. Users can even add their own special sound effects to create a uniquely entertaining performance.

 

Read the project summary

 

PIK3A Retro Gaming Table by spannerspencer

 

PIK3A Retro Gaming Table

 

This simple but highly entertaining project transformed a standard IKEA coffee table into a modern take on the classic arcade console, complete with joysticks and LCD monitor. The Raspberry Pi was used as the 'brains' of the console, interfacing with an Arduino Leonardo that handled the controls.

 

Read the project summary

 

Plex Media Server by biglesp

 

 

Taking advantage of the increased speed and power of the Raspberry Pi 3, Les Pounder created a Plex Media Server that offered rapid indexing of a wide range of media, with scaling CPU and WiFi.

 

Read the project summary

 

Image Detecting Security Camera by shabaz

 

 

This sophisticated security device by Shabaz Yousaf not only detects movement, it discriminates between uninteresting activity - such as a car driving past a road - and potential risks such as the presence of a stranger. Operated by a Raspberry Pi 3, the HAL-CAM 9001 outputs both video and a readable, time-stamped text file, allowing users to quickly browse for relevant activity.

 

Read the project summary

 

Foginator 2000 by CharlesGantt

 

 

A fun project for Halloween, the Foginator 2000 by Charles Gantt is an automated Fog Machine controller utilising the Raspberry Pi Sense HAT. The device trips a sensor when motion is detected, firing off a blast of fog guaranteed to terrify Trick or Treaters.

 

Read the project summary

 

Scary Door by Catwell

 

 

Another ghoulish Halloween project, Cabe Atwell's Scary Door project incorporates a variety of audio and visual effects, all powered by the Raspberry Pi, to create a hilarious and varied set of responses whenever an unwitting trick or treater approaches your home.

 

Read the project summary

 

Project Goldie by Catwell

 

 

 

After his beloved pet Goldfish suffered a near-death experience while he was on holiday, Cabe Atwell was inspired to design a system for remotely monitoring and controlling his fish tank, including feeding, sensing water temperature and managing the filters. This quirky, heartfelt and creative project was a huge hit with our members.

 

Read the project summary

 

IoT Alarm Clock by fvan

 

 

Using a Raspberry Pi with WiFi dongle for wireless connectivity, plus a Pi-Lite LED matrix as a display, this internet-enabled alarm clock taps into railway timetables to adjust the alarm based on real-time schedule updates, programs a variety of radio stations for different alarms and offers quality stereo sound using a Wolfson audio card.

 

Read the project summary

 

Not only do these ten projects demonstrate the power and versatility of the Raspberry Pi, they're also a tribute to the creativity and ingenuity of our community members. As the Raspberry Pi foundation continues to push the boundaries of what can be achieved using IoT technology, we look forward to seeing more exciting and innovative projects here on the element14 community.

 

Are you working on a Raspberry Pi project? Is there a member project that you think deserves to be included on this list? Let us know all your thoughts and ideas in the comments section below.

Filter Blog

By date: By tag: