SlideShare a Scribd company logo
Java Native GPIO Operations
Using Device I/O API
About me…
@jeffprestes
Developer Advocate
Java, PHP, JavaScript Developer
Agenda
 What is not IoT
 What is IoT
 Polymath required skills
 Small history of RaspberryPi
 RaspberryPi Components and slots
 Raspbian – a Debian/Linux to RasberryPi
 Java support to SOC devices
 Java Device I/O
 Lab
 Configure WiFi network (static / dhcp / resolv.conf)
 Upgrade the Raspbian
 Install WiringPi
 Install Java for Embedded devices
This is not IoT… (IMHO)
This is so cool but this is Eletronic!!
And this is not new…
(who has gray hair can say… P)
What is IoT?
Internet
Million of Web
Services
(PayPal, Twitter,
Google, Netflix,
Facebook)
Things
Billions of sensors,
motors, displays,
appliances, toys,
cars, stores, robots
+
And to work with IoT you’re going
to need more skills
You’re going to need to a Polimath
A polymath (Greek: πολυμαθής, polymathēs,
"having learned much")[1] is a person whose
expertise spans a significant number of different
subject areas; such a person is known to draw
on complex bodies of knowledge to solve
specific problems. The term was first used in the
seventeenth century; the related term,
polyhistor, is an ancient term with similar
meaning.
(Source: Wikipedia - http://en.wikipedia.org/wiki/Polymath)
Italian Polymath. What was da Vinci? Scientist?
Engineer? Mathematic? Painter? Sculptor? Musician?
Botanic? Anatomist?
Source: Wikipedia - http://en.wikipedia.org/wiki/Leonardo_da_Vinci
Server Side
Eletronic
(sometimes mechanic
and sculptor on wood or iron)
Client/Desktop
Mobile
(Beacons e Weareables)
Operation Systems
Java Device I/O at Raspberry PI to Build a Candy Vending Machine
History
 Designed in UK, University of
Cambridge, 2006, to be a chip alternative
to computers to students. Also a way to
students rediscover how cool is to work
with Robotic.
It has been projected to educational
purposes but can used in Commercial
ones too.
 Team that have concepted it: Eben Upton, Rob Mullins, Jack Lang and Alan Mycroft
 Raspberry Pi Foundation was created and first alpha boards were tested, 2011
 Sells begins April, 2012
 Model B+ is released in November, 2012
 More than 5 Million already have been sold
Java Device I/O at Raspberry PI to Build a Candy Vending Machine
Raspbian is an unofficial port of Debian Wheezy armhf with compilation settings
adjusted to produce optimized "hard float" code that will run on the Raspberry Pi.
Note: Raspbian is not affiliated with the Raspberry Pi Foundation. Raspbian was created by a small,
dedicated team of developers that are fans of the Raspberry Pi hardware, the educational goals of the
Raspberry Pi Foundation and, of course, the Debian Project.
Best OS to Raspberry Pi nowadays. If you use Ubuntu, you’re going to feeling in
home. All basic Unix commands works on it and almost all basic server-side too:
Apache, Nginx, PHP, Java, Python, MySQL
Default user: pi / Default password: raspberry
And never forget: sudo apt-get install and be happy :D
To install it in your MicroSD card (Recommend 8Gb or more)
http://www.raspberrypi.org/documentation/installation/installing-images
JDK SE for
Embbeded Devices
Since JDK 7, Java SE SDK for Desktop was ported to ARM chips and
JDK 8 is already available.
As Raspberry Pi is based in a ARM chip and runs over a Linux
distribution you’re able to use Java SE
You can run your favorite Java Application Server or create JavaFX
applications
(you don’t need to learn JME or Python anymore :D!)
Device I/O API
Originally part of Java ME library, The Device I/O project is an open source,
Java-level API for accessing generic device peripherals on embedded
devices based on JavaSE. It’s under OpenJDK project.
https://wiki.openjdk.java.net/display/dio/Main
http://docs.oracle.com/javame/8.0/api/dio/api/index.html
Differences between
Device I/O and PI4J
PI4J is an excellent API, however it’s only for RaspberryPi if you would
need to run your APP into a BeagleBone board will have to rewrite all
GPIO access code.
Device I/O, as other Java API, brings abstraction layer over GPIO access
functionallity saving your time and complexity. Write once run anywhere :D
Differences between
Device I/O and PI4J
Also, GPIO map is different in two APIs, check:
Device I/O PI4J
http://docs.oracle.com/javame/8.0/get-started-rpi/piportsapdx.htm
http://pi4j.com/pins/model-b-plus.html
Device I/O API
Device I/O has a configuration file for each board
The Raspberry PI file is
dio.properties-raspberrypi
It has definitions for each GPIO ports
Thus Device I/O can works with different SoC Computers
Device I/O API
Device I/O requires special JDK permissions to access GPIO
Device I/O comes with gpio.policy file
You can map each Pin you’re planning to use or only:
grant {
permission jdk.dio.gpio.GPIOPinPermission "*:*";
permission jdk.dio.DeviceMgmtPermission "*:*", "open";
};
(okay, don’t do this in production kids)
Java Device I/O at Raspberry PI to Build a Candy Vending Machine
Java Device I/O at Raspberry PI to Build a Candy Vending Machine
Java Device I/O at Raspberry PI to Build a Candy Vending Machine
Thanks.
Jeff Prestes
@jeffprestes
Slideshare.com/jeffprestes
Github.com/jeffprestes
@paypaldev
developer.paypal.com
developers.braintreepayments.com
Java Device I/O at Raspberry PI to Build a Candy Vending Machine
Configure your wifi credentials:
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
(file content below)
network={
ssid="iPhone"
psk="43070720"
}
network={
ssid=”<<your-wifi-name-here>>"
psk=”<<your-wifi-password>>"
}
network={
ssid="BoxNet"
psk="hackkitty"
}
Configure your wifi network using static IP:
sudo nano /etc/network/interfaces
(file content below)
auto lo
iface lo inet loopback
iface eth0 inet dhcp
auto wlan0
allow-hotplug wlan0
iface wlan0 inet static
address 192.168.20.218
netmask 255.255.255.0
gateway 192.168.20.1
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet static
Configure your wifi network using DHCP (most used):
sudo nano /etc/network/interfaces
(file content below)
auto lo
iface lo inet loopback
iface eth0 inet dhcp
auto wlan0
allow-hotplug wlan0
iface wlan0 inet dhcp
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp
sudo apt-get update
sudo apt-get dist-upgrade
//Upgrades Raspbian
sudo reboot
//Use Reboot to restart Raspbian safetly
sudo halt
//Use halt to turn off Raspbian safetly
sudo nano /etc/resolv.conf
(file content below)
nameserver 8.8.8.8
nameserver 8.8.4.4
//Google DNS servers
Configure the DNS Servers
Wiring Pi
It is GPIO Interface library for the Raspberry Pi. It’s written in C for the
BCM2835 used in the Raspberry Pi.
WiringPi includes a command-line utility gpio which can be used to
program and setup the GPIO pins.
Wiring Pi
$ sudo apt-get install git-core
$ git clone git://git.drogon.net/wiringPi
$ cd wiringPi
$ git pull origin
$ ./build
Installation
$ gpio -v
$ gpio readall
Test
Get back to your user home directory
(in this case you’re using pi user, remember?)
$ cd ~/
Downloading
JDK SE 8 for Embedded
I will have to download it from your computer as you will have to accept
Oracle’s terms and conditions.
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-arm-downloads-2187472.html
Mac and Linux users: use scp to copy the file
$ scp jdk-<version>-linux-arm-vfp-hflt.gz pi@<your-device-
ip>:/home/pi/jdk-<version>-linux-arm-vfp-hflt.tar.gz
(note that I’ve changed the extention
because the downloaded file came only with .gz extention)
Windows users: use WinSCP to do this
Installing
JDK SE 8 for Embedded
At PI home directory execute:
$ sudo mkdir -p /opt/java
$ sudo chown root:root /opt/java
$ cd /opt/java
$ sudo tar xvzf ~/jdk-<version>-linux-arm-vfp-hflt.tar.gz
Set default java and javac to the new installed JDK.
$ sudo update-alternatives --install /usr/bin/javac javac /opt/jdk-<version>/bin/javac
1
$ sudo update-alternatives --install /usr/bin/java java /opt/jdk-<version>/bin/java 1
$ sudo update-alternatives --config javac
$ sudo update-alternatives --config java
After all, verify with the commands with -verion option.
$ java -version
$ javac -version
Installing
JDK SE 8 for Embedded
Double check if java version is correct for root too:
$ sudo java -version
$ sudo javac –version
This is important because will you need to run your Java application that access
GPIO with root privileges.
Installing
JDK SE 8 for Embedded
Define JAVA_HOME environment variable:
$ sudo nano /etc/environment
And add to it:
JAVA_HOME="/opt/jdk-<version>"
Do the same in your bash profile
$ nano ~/.bashrc
And add to it:
export JAVA_HOME="/opt/java/jdk-<version>"
export PATH=$PATH:$JAVA_HOME/bin
Installing
Java Device I/O
You’ll need to download and compile the library in your Raspberry PI.
Device I/O like other OpenJDK projects uses Mercurial to manage their source
code. You must install it into your Raspberry PI
$ sudo apt-get install mercurial
Create a directory to store the source code and compile it
$ mkdir deviceio
Download it
$ cd deviceio
$ hg clone http://hg.openjdk.java.net/dio/dev
Installing
Java Device I/O
Let’s compile it:
$ export PI_TOOLS=/usr
$ cd dev
$ make
After this, let’s install your Device I/O files in your JRE
$ cp -r build/deviceio/lib/*
$JAVA_HOME/jre/lib
Now let’s get started to talk about good things…
Java Device I/O at Raspberry PI to Build a Candy Vending Machine
Our Lab: Create a Candy
Vending Machine
How it works
Our Lab: Create a Candy
Vending Machine
Let’s use Wiring Pi to test the circuits
$ sudo gpio mode 1 output
$ sudo gpio mode 4 output
$ sudo gpio write 1 1
$ sudo gpio write 1 1
$ sudo gpio write 1 0
$ sudo gpio write 1 0
Our Lab: Create a Candy
Vending Machine
Copy the dio.jar compiled in your Raspberry Pi to your machine
$ scp ~/deviceio/dev/build/jar/dio.jar <your-
user>@<yourmachineip>:~/dio.jar
Or use yout WinSCP
Add it your Maven local repository
$ mvn install:install-file -Dfile=~/dio.jar -DgroupId=jdk.dio -
DartifactId=device-io -Dversion=1.0 -Dpackaging=jar -
DgeneratePom=true
Open the Netbeans and at Team->Git->Clone Repository
https://github.com/jeffprestes/candies-client-native-java.git
Our Lab: Create a Candy
Vending Machine
Java Device I/O at Raspberry PI to Build a Candy Vending Machine
Java Device I/O at Raspberry PI to Build a Candy Vending Machine
Copy the jar compiled with Dependencies to home’s directory of pi user.
Now it’s time to edit GPIO permissions in gpio.policy file
Copy it to home directory
$ cp ~/deviceio/dev/samples/gpio/gpio.policy ~/gpio.policy
And content must be like this
grant {
// permissions for using GPIO pin 18 GPIOLEDSample
permission jdk.dio.gpio.GPIOPinPermission ":18";
permission jdk.dio.gpio.GPIOPinPermission "0:18";
permission jdk.dio.DeviceMgmtPermission "GPIO18:18", "open";
permission jdk.dio.gpio.GPIOPinPermission ":24";
permission jdk.dio.gpio.GPIOPinPermission "0:24";
permission jdk.dio.DeviceMgmtPermission "GPIO24:24", "open";
};
Our Lab: Create a Candy
Vending Machine
Now, let’s start the machine application
$ sudo java
-Djdk.dio.registry=/home/pi/java/dio/config/dio.properties-raspberrypi
-Djava.security.policy=/home/pi/java/nativegpio/gpio.policy
-jar candies.jar iot.eclipse.org jeffprestes/candies/world machineusa 1883
Where:
iot.eclipse.org is the MQTT server
jeffprestes/candies/world is the queue
machineusa is the client name
1883 is the MQTT broker port
Our Lab: Create a Candy
Vending Machine
Our Lab: Create a Candy
Vending Machine
To buy
Create a Premier account in PayPal Sandbox
developer.paypal.com -> Dashboard -> Sandbox -> Accounts ->
Create Account
Later, goto candies.novatrix.com.br in your mobile phone and
use this user as a buyer
Java Device I/O at Raspberry PI to Build a Candy Vending Machine
Java Device I/O at Raspberry PI to Build a Candy Vending Machine
Thanks.
Jeff Prestes
@jeffprestes
Slideshare.com/jeffprestes
Github.com/jeffprestes
@paypaldev
developer.paypal.com
developers.braintreepayments.com

More Related Content

PPTX
Building your own RC Car with Raspberry Pi
PDF
DEVOXX Let's Get Physical: I/O Programming with Java on the Raspberry Pi usin...
PDF
RASPBERRY PI WITH JAVA 8 + Pi4J (Devoxx 2014)
PPTX
[CON3189] JavaOne 2016 - Introduction to Java ME development for the Raspberr...
PPTX
Introduction To Raspberry Pi with Simple GPIO pin Control
ODP
Raspberry Pi and Amateur Radio
PDF
Raspberry pi pico projects raspberry pi projects
PPTX
Building the Internet of Things with Raspberry Pi
Building your own RC Car with Raspberry Pi
DEVOXX Let's Get Physical: I/O Programming with Java on the Raspberry Pi usin...
RASPBERRY PI WITH JAVA 8 + Pi4J (Devoxx 2014)
[CON3189] JavaOne 2016 - Introduction to Java ME development for the Raspberr...
Introduction To Raspberry Pi with Simple GPIO pin Control
Raspberry Pi and Amateur Radio
Raspberry pi pico projects raspberry pi projects
Building the Internet of Things with Raspberry Pi

What's hot (20)

PPTX
Raspberry Pi Using Python
PPTX
Pi Is For Python
PPTX
Getting Started with Raspberry Pi and Arduino
PDF
PyCon_India_2017_MicroPython_Ayan
PPTX
Con7968 let's get physical - io programming using pi4 j
PDF
Getting started with AGL using a Raspberry Pi
PDF
My presentation raspberry pi
PDF
Exploring Raspberry Pi
ODP
Introduction to Raspberry Pi and GPIO
PPTX
Con3187 Creating Industrial Middleware with Java ME and Single-Board Computers
PDF
Raspberry pi tutorial
PDF
Getting Started with Embedded Python: MicroPython and CircuitPython
PDF
Interfacing the Raspberry Pi to the World
PDF
Rapidly developing IoT (Internet of Things) applications - Part 2: Arduino, B...
PDF
Raspberry Pi and Amateur Radio - 2020 update
PDF
Java fx on raspberry pi gerrit grunwald
PDF
[Forward4 Webinar 2016] Building IoT Prototypes w/ Raspberry Pi
PPT
Smart Wireless Surveillance Monitoring using RASPBERRY PI
PDF
Exploring Your Apple M1 devices with Open Source Tools
Raspberry Pi Using Python
Pi Is For Python
Getting Started with Raspberry Pi and Arduino
PyCon_India_2017_MicroPython_Ayan
Con7968 let's get physical - io programming using pi4 j
Getting started with AGL using a Raspberry Pi
My presentation raspberry pi
Exploring Raspberry Pi
Introduction to Raspberry Pi and GPIO
Con3187 Creating Industrial Middleware with Java ME and Single-Board Computers
Raspberry pi tutorial
Getting Started with Embedded Python: MicroPython and CircuitPython
Interfacing the Raspberry Pi to the World
Rapidly developing IoT (Internet of Things) applications - Part 2: Arduino, B...
Raspberry Pi and Amateur Radio - 2020 update
Java fx on raspberry pi gerrit grunwald
[Forward4 Webinar 2016] Building IoT Prototypes w/ Raspberry Pi
Smart Wireless Surveillance Monitoring using RASPBERRY PI
Exploring Your Apple M1 devices with Open Source Tools
Ad

Viewers also liked (20)

PPTX
RaspberryPi + IoT - Lab to switch on and off a light bulb
ODP
Android Based Robots
PPTX
IoT - IT 423 ppt
PPTX
Chapter 10:Understanding Java Related Platforms and Integration Technologies
PPTX
Why Java
PDF
J2EE vs JavaEE
PPT
Java JSON Parser Comparison
PDF
ICT-104 bill acceptor protocol
PPTX
Facebook Messenger and Go
PPTX
Plant monitoring 101
PPT
Technological advancements
PPTX
Aeronautical communication
PPTX
Will SCADA Systems Survive? The Future of Distributed Management Systems
PPTX
IoT in Agriculture
PPTX
Connected Agricultural services and internet of things..
PDF
IoT for Agriculture - Drones / UAV
PDF
Desktop apps with node webkit
PDF
Ingesting Drone Data into Big Data Platforms
PPT
Internet of Things and its applications
RaspberryPi + IoT - Lab to switch on and off a light bulb
Android Based Robots
IoT - IT 423 ppt
Chapter 10:Understanding Java Related Platforms and Integration Technologies
Why Java
J2EE vs JavaEE
Java JSON Parser Comparison
ICT-104 bill acceptor protocol
Facebook Messenger and Go
Plant monitoring 101
Technological advancements
Aeronautical communication
Will SCADA Systems Survive? The Future of Distributed Management Systems
IoT in Agriculture
Connected Agricultural services and internet of things..
IoT for Agriculture - Drones / UAV
Desktop apps with node webkit
Ingesting Drone Data into Big Data Platforms
Internet of Things and its applications
Ad

Similar to Java Device I/O at Raspberry PI to Build a Candy Vending Machine (20)

PPTX
How to make your Money Machine with Internet of Things
PDF
Raspi_TOR_Access_Point_BenMoore
PDF
Raspberry pi Board Hardware & Software Setup
PPTX
Raspberry Pi Session - 22_11_2014
ODP
Raspberry Pi introduction
PPTX
Raspberry Pi (Introduction)
PPTX
Raspberry Pi Free Session - 20_09_2014
PDF
Dependencies Managers in C/C++. Using stdcpp 2014
PPTX
Connected hardware for Software Engineers 101
PPTX
Raspberry Pi - Unlocking New Ideas for Your Library
PPTX
Java on Raspberry Pi Lab
PPTX
Custom Buildpacks and Data Services
PDF
Porting your favourite cmdline tool to Android
PDF
Apache Bigtop and ARM64 / AArch64 - Empowering Big Data Everywhere
PDF
Docker module 1
PDF
Run Your Java Code on Cloud Foundry - Andy Piper (Pivotal)
PDF
Run your Java apps on Cloud Foundry
PDF
Advanced View of Projects Raspberry Pi List - Raspberry PI Projects.pdf
PDF
manual_2020_Cyber Physical System.pdf
PDF
Hadoop on raspberry pi PART 1
How to make your Money Machine with Internet of Things
Raspi_TOR_Access_Point_BenMoore
Raspberry pi Board Hardware & Software Setup
Raspberry Pi Session - 22_11_2014
Raspberry Pi introduction
Raspberry Pi (Introduction)
Raspberry Pi Free Session - 20_09_2014
Dependencies Managers in C/C++. Using stdcpp 2014
Connected hardware for Software Engineers 101
Raspberry Pi - Unlocking New Ideas for Your Library
Java on Raspberry Pi Lab
Custom Buildpacks and Data Services
Porting your favourite cmdline tool to Android
Apache Bigtop and ARM64 / AArch64 - Empowering Big Data Everywhere
Docker module 1
Run Your Java Code on Cloud Foundry - Andy Piper (Pivotal)
Run your Java apps on Cloud Foundry
Advanced View of Projects Raspberry Pi List - Raspberry PI Projects.pdf
manual_2020_Cyber Physical System.pdf
Hadoop on raspberry pi PART 1

More from Jeff Prestes (20)

PPTX
Começando com Quorum - versão 2.6
PDF
Solidity 0.6.x
PPTX
Desmistificando blockchain
PPTX
Aumento da eficácia jurídica com Smart Contracts
PPTX
Go (golang) - Porque ele deve ser a linguagem da sua próxima API
PPTX
Chatbots and Internet of Things
PPTX
Physical web
PPTX
Beacons, Raspberry Pi & Node.js
PPTX
Eddystone Beacons - Physical Web - Giving a URL to All Objects
PPTX
Making Payments in Android Easy
PPTX
Kraken.js - Giving Extra Arms to your Node.js App
PPTX
Mobile Payments Workshop
PPTX
Interact your wearable and an iot device
PPTX
Fazendo maquinas para ganhar dinheiro com Internet das Coisas
PDF
Test A/B
PPTX
Let your stuff talk!
PPTX
Express checkout PayPal
PPTX
Quercus - Running PHP over Java
PPTX
Open ID Connect
PPTX
Beacon - Revolutionizing Mobile Apps In-Context
Começando com Quorum - versão 2.6
Solidity 0.6.x
Desmistificando blockchain
Aumento da eficácia jurídica com Smart Contracts
Go (golang) - Porque ele deve ser a linguagem da sua próxima API
Chatbots and Internet of Things
Physical web
Beacons, Raspberry Pi & Node.js
Eddystone Beacons - Physical Web - Giving a URL to All Objects
Making Payments in Android Easy
Kraken.js - Giving Extra Arms to your Node.js App
Mobile Payments Workshop
Interact your wearable and an iot device
Fazendo maquinas para ganhar dinheiro com Internet das Coisas
Test A/B
Let your stuff talk!
Express checkout PayPal
Quercus - Running PHP over Java
Open ID Connect
Beacon - Revolutionizing Mobile Apps In-Context

Recently uploaded (20)

PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Getting Started with Data Integration: FME Form 101
PDF
Network Security Unit 5.pdf for BCA BBA.
PPT
Teaching material agriculture food technology
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
Spectroscopy.pptx food analysis technology
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
1. Introduction to Computer Programming.pptx
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
A Presentation on Artificial Intelligence
PPTX
Tartificialntelligence_presentation.pptx
PPTX
Machine Learning_overview_presentation.pptx
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PPTX
Big Data Technologies - Introduction.pptx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Advanced methodologies resolving dimensionality complications for autism neur...
Getting Started with Data Integration: FME Form 101
Network Security Unit 5.pdf for BCA BBA.
Teaching material agriculture food technology
Per capita expenditure prediction using model stacking based on satellite ima...
Programs and apps: productivity, graphics, security and other tools
Spectroscopy.pptx food analysis technology
The Rise and Fall of 3GPP – Time for a Sabbatical?
1. Introduction to Computer Programming.pptx
Accuracy of neural networks in brain wave diagnosis of schizophrenia
“AI and Expert System Decision Support & Business Intelligence Systems”
A Presentation on Artificial Intelligence
Tartificialntelligence_presentation.pptx
Machine Learning_overview_presentation.pptx
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Unlocking AI with Model Context Protocol (MCP)
Assigned Numbers - 2025 - Bluetooth® Document
Big Data Technologies - Introduction.pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Profit Center Accounting in SAP S/4HANA, S4F28 Col11

Java Device I/O at Raspberry PI to Build a Candy Vending Machine

  • 1. Java Native GPIO Operations Using Device I/O API
  • 3. Agenda  What is not IoT  What is IoT  Polymath required skills  Small history of RaspberryPi  RaspberryPi Components and slots  Raspbian – a Debian/Linux to RasberryPi  Java support to SOC devices  Java Device I/O  Lab  Configure WiFi network (static / dhcp / resolv.conf)  Upgrade the Raspbian  Install WiringPi  Install Java for Embedded devices
  • 4. This is not IoT… (IMHO) This is so cool but this is Eletronic!!
  • 5. And this is not new… (who has gray hair can say… P)
  • 6. What is IoT? Internet Million of Web Services (PayPal, Twitter, Google, Netflix, Facebook) Things Billions of sensors, motors, displays, appliances, toys, cars, stores, robots +
  • 7. And to work with IoT you’re going to need more skills You’re going to need to a Polimath A polymath (Greek: πολυμαθής, polymathēs, "having learned much")[1] is a person whose expertise spans a significant number of different subject areas; such a person is known to draw on complex bodies of knowledge to solve specific problems. The term was first used in the seventeenth century; the related term, polyhistor, is an ancient term with similar meaning. (Source: Wikipedia - http://en.wikipedia.org/wiki/Polymath)
  • 8. Italian Polymath. What was da Vinci? Scientist? Engineer? Mathematic? Painter? Sculptor? Musician? Botanic? Anatomist? Source: Wikipedia - http://en.wikipedia.org/wiki/Leonardo_da_Vinci
  • 9. Server Side Eletronic (sometimes mechanic and sculptor on wood or iron) Client/Desktop Mobile (Beacons e Weareables) Operation Systems
  • 11. History  Designed in UK, University of Cambridge, 2006, to be a chip alternative to computers to students. Also a way to students rediscover how cool is to work with Robotic. It has been projected to educational purposes but can used in Commercial ones too.  Team that have concepted it: Eben Upton, Rob Mullins, Jack Lang and Alan Mycroft  Raspberry Pi Foundation was created and first alpha boards were tested, 2011  Sells begins April, 2012  Model B+ is released in November, 2012  More than 5 Million already have been sold
  • 13. Raspbian is an unofficial port of Debian Wheezy armhf with compilation settings adjusted to produce optimized "hard float" code that will run on the Raspberry Pi. Note: Raspbian is not affiliated with the Raspberry Pi Foundation. Raspbian was created by a small, dedicated team of developers that are fans of the Raspberry Pi hardware, the educational goals of the Raspberry Pi Foundation and, of course, the Debian Project. Best OS to Raspberry Pi nowadays. If you use Ubuntu, you’re going to feeling in home. All basic Unix commands works on it and almost all basic server-side too: Apache, Nginx, PHP, Java, Python, MySQL Default user: pi / Default password: raspberry And never forget: sudo apt-get install and be happy :D To install it in your MicroSD card (Recommend 8Gb or more) http://www.raspberrypi.org/documentation/installation/installing-images
  • 14. JDK SE for Embbeded Devices Since JDK 7, Java SE SDK for Desktop was ported to ARM chips and JDK 8 is already available. As Raspberry Pi is based in a ARM chip and runs over a Linux distribution you’re able to use Java SE You can run your favorite Java Application Server or create JavaFX applications (you don’t need to learn JME or Python anymore :D!)
  • 15. Device I/O API Originally part of Java ME library, The Device I/O project is an open source, Java-level API for accessing generic device peripherals on embedded devices based on JavaSE. It’s under OpenJDK project. https://wiki.openjdk.java.net/display/dio/Main http://docs.oracle.com/javame/8.0/api/dio/api/index.html
  • 16. Differences between Device I/O and PI4J PI4J is an excellent API, however it’s only for RaspberryPi if you would need to run your APP into a BeagleBone board will have to rewrite all GPIO access code. Device I/O, as other Java API, brings abstraction layer over GPIO access functionallity saving your time and complexity. Write once run anywhere :D
  • 17. Differences between Device I/O and PI4J Also, GPIO map is different in two APIs, check: Device I/O PI4J http://docs.oracle.com/javame/8.0/get-started-rpi/piportsapdx.htm http://pi4j.com/pins/model-b-plus.html
  • 18. Device I/O API Device I/O has a configuration file for each board The Raspberry PI file is dio.properties-raspberrypi It has definitions for each GPIO ports Thus Device I/O can works with different SoC Computers
  • 19. Device I/O API Device I/O requires special JDK permissions to access GPIO Device I/O comes with gpio.policy file You can map each Pin you’re planning to use or only: grant { permission jdk.dio.gpio.GPIOPinPermission "*:*"; permission jdk.dio.DeviceMgmtPermission "*:*", "open"; }; (okay, don’t do this in production kids)
  • 25. Configure your wifi credentials: sudo nano /etc/wpa_supplicant/wpa_supplicant.conf (file content below) network={ ssid="iPhone" psk="43070720" } network={ ssid=”<<your-wifi-name-here>>" psk=”<<your-wifi-password>>" } network={ ssid="BoxNet" psk="hackkitty" }
  • 26. Configure your wifi network using static IP: sudo nano /etc/network/interfaces (file content below) auto lo iface lo inet loopback iface eth0 inet dhcp auto wlan0 allow-hotplug wlan0 iface wlan0 inet static address 192.168.20.218 netmask 255.255.255.0 gateway 192.168.20.1 wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf iface default inet static
  • 27. Configure your wifi network using DHCP (most used): sudo nano /etc/network/interfaces (file content below) auto lo iface lo inet loopback iface eth0 inet dhcp auto wlan0 allow-hotplug wlan0 iface wlan0 inet dhcp wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf iface default inet dhcp
  • 28. sudo apt-get update sudo apt-get dist-upgrade //Upgrades Raspbian sudo reboot //Use Reboot to restart Raspbian safetly sudo halt //Use halt to turn off Raspbian safetly
  • 29. sudo nano /etc/resolv.conf (file content below) nameserver 8.8.8.8 nameserver 8.8.4.4 //Google DNS servers Configure the DNS Servers
  • 30. Wiring Pi It is GPIO Interface library for the Raspberry Pi. It’s written in C for the BCM2835 used in the Raspberry Pi. WiringPi includes a command-line utility gpio which can be used to program and setup the GPIO pins.
  • 31. Wiring Pi $ sudo apt-get install git-core $ git clone git://git.drogon.net/wiringPi $ cd wiringPi $ git pull origin $ ./build Installation $ gpio -v $ gpio readall Test
  • 32. Get back to your user home directory (in this case you’re using pi user, remember?) $ cd ~/
  • 33. Downloading JDK SE 8 for Embedded I will have to download it from your computer as you will have to accept Oracle’s terms and conditions. http://www.oracle.com/technetwork/java/javase/downloads/jdk8-arm-downloads-2187472.html Mac and Linux users: use scp to copy the file $ scp jdk-<version>-linux-arm-vfp-hflt.gz pi@<your-device- ip>:/home/pi/jdk-<version>-linux-arm-vfp-hflt.tar.gz (note that I’ve changed the extention because the downloaded file came only with .gz extention) Windows users: use WinSCP to do this
  • 34. Installing JDK SE 8 for Embedded At PI home directory execute: $ sudo mkdir -p /opt/java $ sudo chown root:root /opt/java $ cd /opt/java $ sudo tar xvzf ~/jdk-<version>-linux-arm-vfp-hflt.tar.gz Set default java and javac to the new installed JDK. $ sudo update-alternatives --install /usr/bin/javac javac /opt/jdk-<version>/bin/javac 1 $ sudo update-alternatives --install /usr/bin/java java /opt/jdk-<version>/bin/java 1 $ sudo update-alternatives --config javac $ sudo update-alternatives --config java After all, verify with the commands with -verion option. $ java -version $ javac -version
  • 35. Installing JDK SE 8 for Embedded Double check if java version is correct for root too: $ sudo java -version $ sudo javac –version This is important because will you need to run your Java application that access GPIO with root privileges.
  • 36. Installing JDK SE 8 for Embedded Define JAVA_HOME environment variable: $ sudo nano /etc/environment And add to it: JAVA_HOME="/opt/jdk-<version>" Do the same in your bash profile $ nano ~/.bashrc And add to it: export JAVA_HOME="/opt/java/jdk-<version>" export PATH=$PATH:$JAVA_HOME/bin
  • 37. Installing Java Device I/O You’ll need to download and compile the library in your Raspberry PI. Device I/O like other OpenJDK projects uses Mercurial to manage their source code. You must install it into your Raspberry PI $ sudo apt-get install mercurial Create a directory to store the source code and compile it $ mkdir deviceio Download it $ cd deviceio $ hg clone http://hg.openjdk.java.net/dio/dev
  • 38. Installing Java Device I/O Let’s compile it: $ export PI_TOOLS=/usr $ cd dev $ make After this, let’s install your Device I/O files in your JRE $ cp -r build/deviceio/lib/* $JAVA_HOME/jre/lib
  • 39. Now let’s get started to talk about good things…
  • 41. Our Lab: Create a Candy Vending Machine How it works
  • 42. Our Lab: Create a Candy Vending Machine
  • 43. Let’s use Wiring Pi to test the circuits $ sudo gpio mode 1 output $ sudo gpio mode 4 output $ sudo gpio write 1 1 $ sudo gpio write 1 1 $ sudo gpio write 1 0 $ sudo gpio write 1 0 Our Lab: Create a Candy Vending Machine
  • 44. Copy the dio.jar compiled in your Raspberry Pi to your machine $ scp ~/deviceio/dev/build/jar/dio.jar <your- user>@<yourmachineip>:~/dio.jar Or use yout WinSCP Add it your Maven local repository $ mvn install:install-file -Dfile=~/dio.jar -DgroupId=jdk.dio - DartifactId=device-io -Dversion=1.0 -Dpackaging=jar - DgeneratePom=true Open the Netbeans and at Team->Git->Clone Repository https://github.com/jeffprestes/candies-client-native-java.git Our Lab: Create a Candy Vending Machine
  • 47. Copy the jar compiled with Dependencies to home’s directory of pi user. Now it’s time to edit GPIO permissions in gpio.policy file Copy it to home directory $ cp ~/deviceio/dev/samples/gpio/gpio.policy ~/gpio.policy And content must be like this grant { // permissions for using GPIO pin 18 GPIOLEDSample permission jdk.dio.gpio.GPIOPinPermission ":18"; permission jdk.dio.gpio.GPIOPinPermission "0:18"; permission jdk.dio.DeviceMgmtPermission "GPIO18:18", "open"; permission jdk.dio.gpio.GPIOPinPermission ":24"; permission jdk.dio.gpio.GPIOPinPermission "0:24"; permission jdk.dio.DeviceMgmtPermission "GPIO24:24", "open"; }; Our Lab: Create a Candy Vending Machine
  • 48. Now, let’s start the machine application $ sudo java -Djdk.dio.registry=/home/pi/java/dio/config/dio.properties-raspberrypi -Djava.security.policy=/home/pi/java/nativegpio/gpio.policy -jar candies.jar iot.eclipse.org jeffprestes/candies/world machineusa 1883 Where: iot.eclipse.org is the MQTT server jeffprestes/candies/world is the queue machineusa is the client name 1883 is the MQTT broker port Our Lab: Create a Candy Vending Machine
  • 49. Our Lab: Create a Candy Vending Machine To buy Create a Premier account in PayPal Sandbox developer.paypal.com -> Dashboard -> Sandbox -> Accounts -> Create Account Later, goto candies.novatrix.com.br in your mobile phone and use this user as a buyer