You can easily build a device that will notify you when you have a Facebook Notification using Wyliodrin and Intel Galileo. I will show you how.
We will use Python language for this application because it is perfect for what we need. So, let's create a new project in Wyliodrin and name it FacebookNotifier. Erase all the auto-generated code and start coding from scratch.
The program is split in 3 submodules:
You can interact with the Galileo's pins using the Linux sys interface. You can set pin direction (output or input) and value (high or low) using simple shell commands. More details here.
We can do anything we like with Galileo's pins by writing or reading from files so almost any programming language can be used for this task.
We said that we need a function to initialize de pins so here it is:
def pins_init(): // 1 try: pin_export = open("/sys/class/gpio/export","w") pin_export.write("27") pin_export.close() except IOError: print "GPIO already exists" // 2 gpio = open("/sys/class/gpio/gpio27/direction","w") gpio.write("out") gpio.close()
Setting a value on a pin is as simple as writing to a file:
def write_led(value): f = open("/sys/class/gpio/gpio27/value","w") f.write(str(value)) f.close
The variable “value” we'll be 0 or 1.
For this, we will use Facebook Graph. Click here.
You will need to generate an Acess Token. Click on “Get Access Token”, then “Extended Permissions” and select “manage_notification”. Using this access token you can make request at URL:
This will return you some information in JSON format. The only field that we are interested in is “summary” at the end of the JSON. When you have a new unread notification, “summary” length will not be zero.
pins_init() while True: r = urllib2.urlopen('https://graph.facebook.com/me/notifications?access_token=your_access_token') html = r.read() data = json.loads(html); if len(data['summary']) == 0: write_led(0) else: write_led(1) time.sleep(3)
Now you have your own Notifier and you will never miss a Facebook Notification again.
You can go further with this project and add a Buzzer that will make noise when you receive a new notification and an LCD that will show the latest notification.
Thank you and good luck!