SlideShare a Scribd company logo
BUILD A JAVA
WEATHER STATION
USE YOUR RASPBERRY PI2 AND DEVELOP A WEB CLIENT
MARCO PIRRUCCIO
Research and Development Director, Partner @ Kettydo+ srl
E-mail marcopirruccio@gmail.com
LinkedIn www.linkedin.com/in/marcopirruccio
SPOT THE DIFFERENCES
HARDWARE SHOPPING LIST
• Raspberry Pi2
• DHT22 (temperature, humidity)
• BMP180 (temperature, pressure, altitude)
• ML8511 (UV intensity)
• TGS2600 (air contaminants)
• MCP3800 (ADC for ML8511 and TGS2600)
• A red and a green LED
• A tactile button switch
SOFTWARE INGREDIENTS
On the Raspberry Pi
• Java 8
• Pi4J and WiringPi
• MQTT (Eclipse Paho Java client)
On the web client
• WebSockets (Eclipse Paho JavaScript client)
• JavaScript: jQuery, HighCharts
• HTML, CSS
THE SKETCH
Fritzing
ARCHITECTURE
MQTT (MESSAGE QUEUING TELEMETRY TRANSPORT)
• MQTT is a “machine-to-machine” (M2M) or “Internet of Things” (IoT) connectivity protocol.
• It was designed as an extremely lightweight publish/subscribe messaging transport.
• It was designed for constrained devices and low-bandwidth, high-latency or unreliable networks.
• MQTT was invented by Dr Andy Stanford-Clark of IBM and Arlen Nipper of Arcom (now Eurotech) in 1999.
• It is an application protocol over TCP/IP.
• Quality of service levels:
• 0: at most once delivery
• 1: at least once delivery
• 2: exactly once delivery (there is an increased overhead associated with this quality of service)
WEBSOCKETS
• The WebSockets specification was developed as part of the HTML5 initiative.
• The WebSockets standard defines a full-duplex single socket connection over which messages can be
sent between client and server.
• WebSockets provide an enormous reduction in unnecessary network traffic and latency compared to
the unscalable polling and long-polling solutions that were used to simulate a full-duplex connection by
maintaining two connections.
JAVA, PI4J, WIRINGPI
• Raspbian includes the official Oracle Java 8 for ARM since the end of 2013. Older versions can install it using apt-get.
• The Pi4J project is intended to provide a friendly object-oriented I/O API and implementation libraries for Java Programmers
to access the full I/O capabilities of the Raspberry Pi platform.
• It abstracts the low-level native integration and interrupt monitoring to enable Java programmers to focus on implementing
their application business logic.
• Main features:
• Control, read and write GPIO pin states
• Listen for GPIO pin state changes (interrupt-based; not polling)
• I2C, SPI, RS232 communication
• WiringPi is a GPIO access library written in C for the BCM2835.
WEATHER STATION MAIN CLASS
WeatherStationReader reader = new WeatherStationReader();
WeatherStationWriter writer = WeatherStationWriterFactory.getWriter(Writer.MQTT);
Runtime.getRuntime().addShutdownHook(new Thread() {
public void run() {
reader.shutdown();
writer.close();
}
});
while (true) {
WeatherStationData data = reader.read();
writer.write(data);
Thread.sleep(2000);
}
WEATHER STATION READER: INITIALIZATION
GpioController controller = GpioFactory.getInstance();
MCP3008 adc = new MCP3008();
ML8511 uv = new ML8511(adc, ML8511_ADC_CHANNEL);
TGS2600 gas = new TGS2600(adc, TGS2600_ADC_CHANNEL);
BMP180 bar = new BMP180();
DHT22 t = new DHT22(DHT22_PIN);
GpioPinDigitalInput button = controller.provisionDigitalInputPin(BUTTON_GPIO, PinPullResistance.PULL_UP);
button.addListener(new GpioPinListenerDigital() {
public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {
System.exit(0);
}
});
ActivityNotifier an = new ActivityNotifier(READ_ACTIVITY_NOTIFIER_GPIO, "readerLed");
WEATHER STATION READER: READING SENSORS
an.notifyActivity();
WeatherStationData res = new WeatherStationData();
DHT22Response th = t.read();
res.setTemperature((float) th.getTemperature());
res.setHumidity((float) th.getHumidity());
gas.setReferenceHumidity(res.getHumidity()); gas.setReferenceTemperature(res.getTemperature());
TGS2600Response air = gas.read();
res.setAirQuality(air.getResistance()); res.setEthanol((int) air.getC2h5ohPPM()); res.setButane((int) air.getC4h10PPM());
res.setHydrogen((int) air.getH2PPM());
float uvIntensity = uv.read(); res.setUvIntensity(uvIntensity);
final float pressure = bar.readPressure(); res.setPressure(pressure / 100);
WEATHER STATION WRITER: INITIALIZATION
String broker = "tcp://iot.eclipse.org:1883";
String clientId = WeatherStation.class.getName();
MemoryPersistence persistence = new MemoryPersistence();
MqttClient client = new MqttClient(broker, clientId, persistence);
MqttConnectOptions connOpts = new MqttConnectOptions();
connOpts.setCleanSession(true);
client.connect(connOpts);
ActivityNotifier an = new ActivityNotifier(WRITE_ACTIVITY_NOTIFIER_GPIO, "writerLed");
WEATHER STATION WRITER: SENDING DATA
String topic = "/WeatherStation";
int qos = 2;
String json = jsonSerializer.serialize(data);
an.notifyActivity();
MqttMessage message = new MqttMessage(json.getBytes());
message.setQos(qos);
client.publish(topic, message);
THE WEB CLIENT: HTML MARKUP
<div id="container-main"></div>
<div>
<div id="container-uv"></div>
<div id="container-aq"></div>
<div id="container-gas">
<table>
<thead>
<tr><td>PPM</td></tr>
</thead>
<tbody>
<tr><td>Ethanol</td><td id="ethanol">0</td></tr>
<tr><td>Butane</td><td id="butane">0</td></tr>
<tr><td>Hydrogen</td><td id="hydrogen">0</td></tr>
</tbody>
</table>
</div>
</div>
THE WEB CLIENT: WEBSOCKET
var host = 'ws://iot.eclipse.org/ws';
var topic = '/WeatherStation';
var clientId = "WeatherStationClient";
var client = new Paho.MQTT.Client(host, clientId);
client.onConnectionLost = function(responseObject) { ... };
client.onMessageArrived = function(message) { ... };
client.connect({
onSuccess : function() {
client.subscribe(topic);
}
});
THE WEB CLIENT: CHARTS
client.onMessageArrived = function(message) {
var data = JSON.parse(message.payloadString);
var chart = $('#container-main').highcharts();
chart.series[0].addPoint([data.timestamp, data.temperature]);
chart.series[1].addPoint([data.timestamp, data.humidity]);
chart.series[2].addPoint([data.timestamp, data.pressure]);
chart.redraw();
chart = $('#container-uv').highcharts();
var point = chart.series[0].points[0];
point.update(parseFloat(data.uvIntensity.toFixed(2)));
chart = $('#container-aq').highcharts();
point = chart.series[0].points[0];
point.update(parseInt(data.airQuality.toFixed(0)));
$('#ethanol').html(data.ethanol);
$('#butane').html(data.butane);
$('#hydrogen').html(data.hydrogen);
};
THE WEB CLIENT: UI
VIEW A LIVE DEMO AT BOOTH MAK 72
REFERENCES
• http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/mqtt-v3.1.1.html
• https://eclipse.org/paho/clients/java/
• https://www.websocket.org/
• https://eclipse.org/paho/clients/js/
• http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
• http://pi4j.com/
• http://wiringpi.com/
• http://www.highcharts.com/
THANKS
Q & A
Ad

More Related Content

Viewers also liked (7)

Raspberry Pi with Java 8
Raspberry Pi with Java 8Raspberry Pi with Java 8
Raspberry Pi with Java 8
javafxpert
 
MQTT with Java - a protocol for IoT and M2M communication
MQTT with Java - a protocol for IoT and M2M communicationMQTT with Java - a protocol for IoT and M2M communication
MQTT with Java - a protocol for IoT and M2M communication
Christian Götz
 
MQTT, Eclipse Paho and Java - Messaging for the Internet of Things
MQTT, Eclipse Paho and Java - Messaging for the Internet of ThingsMQTT, Eclipse Paho and Java - Messaging for the Internet of Things
MQTT, Eclipse Paho and Java - Messaging for the Internet of Things
Andy Piper
 
Low Cost HD Surveillance Camera using Raspberry PI
Low Cost HD Surveillance Camera using Raspberry PILow Cost HD Surveillance Camera using Raspberry PI
Low Cost HD Surveillance Camera using Raspberry PI
Varun A M
 
Con7968 let's get physical - io programming using pi4 j
Con7968   let's get physical - io programming using pi4 jCon7968   let's get physical - io programming using pi4 j
Con7968 let's get physical - io programming using pi4 j
savageautomate
 
Home Automation Using RPI
Home Automation Using  RPIHome Automation Using  RPI
Home Automation Using RPI
Ankara JUG
 
Internet of things using Raspberry Pi
Internet of things using Raspberry PiInternet of things using Raspberry Pi
Internet of things using Raspberry Pi
Yash Gajera
 
Raspberry Pi with Java 8
Raspberry Pi with Java 8Raspberry Pi with Java 8
Raspberry Pi with Java 8
javafxpert
 
MQTT with Java - a protocol for IoT and M2M communication
MQTT with Java - a protocol for IoT and M2M communicationMQTT with Java - a protocol for IoT and M2M communication
MQTT with Java - a protocol for IoT and M2M communication
Christian Götz
 
MQTT, Eclipse Paho and Java - Messaging for the Internet of Things
MQTT, Eclipse Paho and Java - Messaging for the Internet of ThingsMQTT, Eclipse Paho and Java - Messaging for the Internet of Things
MQTT, Eclipse Paho and Java - Messaging for the Internet of Things
Andy Piper
 
Low Cost HD Surveillance Camera using Raspberry PI
Low Cost HD Surveillance Camera using Raspberry PILow Cost HD Surveillance Camera using Raspberry PI
Low Cost HD Surveillance Camera using Raspberry PI
Varun A M
 
Con7968 let's get physical - io programming using pi4 j
Con7968   let's get physical - io programming using pi4 jCon7968   let's get physical - io programming using pi4 j
Con7968 let's get physical - io programming using pi4 j
savageautomate
 
Home Automation Using RPI
Home Automation Using  RPIHome Automation Using  RPI
Home Automation Using RPI
Ankara JUG
 
Internet of things using Raspberry Pi
Internet of things using Raspberry PiInternet of things using Raspberry Pi
Internet of things using Raspberry Pi
Yash Gajera
 

Similar to Build a Java and Raspberry Pi weather station (20)

Using Eclipse MQTT & Sparkplug as your IIoT Digital Transformation Toolkit | ...
Using Eclipse MQTT & Sparkplug as your IIoT Digital Transformation Toolkit | ...Using Eclipse MQTT & Sparkplug as your IIoT Digital Transformation Toolkit | ...
Using Eclipse MQTT & Sparkplug as your IIoT Digital Transformation Toolkit | ...
Eclipse IoT
 
IoT Seminar (Oct. 2016) Jong Young Lee - MDS Technology
IoT Seminar (Oct. 2016) Jong Young Lee - MDS TechnologyIoT Seminar (Oct. 2016) Jong Young Lee - MDS Technology
IoT Seminar (Oct. 2016) Jong Young Lee - MDS Technology
Open Mobile Alliance
 
Pradeep_Embedded
Pradeep_EmbeddedPradeep_Embedded
Pradeep_Embedded
pradeep22kumark
 
Home automation using IoT and AWS Cloud technology
Home automation using IoT and AWS Cloud technologyHome automation using IoT and AWS Cloud technology
Home automation using IoT and AWS Cloud technology
ratthaslip ranokphanuwat
 
M.Tech Internet of Things Unit - III.pptx
M.Tech Internet of Things Unit - III.pptxM.Tech Internet of Things Unit - III.pptx
M.Tech Internet of Things Unit - III.pptx
AvinashAvuthu2
 
FPGA Implementation of Real Time Data Acquisition System Using Micro blaze Pr...
FPGA Implementation of Real Time Data Acquisition System Using Micro blaze Pr...FPGA Implementation of Real Time Data Acquisition System Using Micro blaze Pr...
FPGA Implementation of Real Time Data Acquisition System Using Micro blaze Pr...
Editor IJCATR
 
IRJET- Raspberry Pi and NodeMCU based Home Automation System
IRJET- Raspberry Pi and NodeMCU based Home Automation SystemIRJET- Raspberry Pi and NodeMCU based Home Automation System
IRJET- Raspberry Pi and NodeMCU based Home Automation System
IRJET Journal
 
174085193 pic-prgm-manual
174085193 pic-prgm-manual174085193 pic-prgm-manual
174085193 pic-prgm-manual
Arun Shan
 
OpenCV acceleration battle:OpenCL on Firefly-RK3288(MALI-T764) vs. FPGA on Ze...
OpenCV acceleration battle:OpenCL on Firefly-RK3288(MALI-T764) vs. FPGA on Ze...OpenCV acceleration battle:OpenCL on Firefly-RK3288(MALI-T764) vs. FPGA on Ze...
OpenCV acceleration battle:OpenCL on Firefly-RK3288(MALI-T764) vs. FPGA on Ze...
Industrial Technology Research Institute (ITRI)(工業技術研究院, 工研院)
 
project seminor
project seminorproject seminor
project seminor
Ramesh Naik Banothu
 
NI Compact RIO Platform
NI Compact RIO PlatformNI Compact RIO Platform
NI Compact RIO Platform
jlai
 
Using raspberry pi to sense temperature and relative humidity
Using raspberry pi to sense temperature and relative humidityUsing raspberry pi to sense temperature and relative humidity
Using raspberry pi to sense temperature and relative humidity
IRJET Journal
 
Eclipse Edje: A Java API for Microcontrollers
Eclipse Edje: A Java API for MicrocontrollersEclipse Edje: A Java API for Microcontrollers
Eclipse Edje: A Java API for Microcontrollers
MicroEJ
 
20081114 Friday Food iLabt Bart Joris
20081114 Friday Food iLabt Bart Joris20081114 Friday Food iLabt Bart Joris
20081114 Friday Food iLabt Bart Joris
imec.archive
 
Industrial Hazard Monitoring using IOT
Industrial Hazard Monitoring using IOTIndustrial Hazard Monitoring using IOT
Industrial Hazard Monitoring using IOT
Ayush Chhangani
 
Android Things in action
Android Things in actionAndroid Things in action
Android Things in action
Stefano Sanna
 
Control System_Training cdpl project nar
Control System_Training cdpl project narControl System_Training cdpl project nar
Control System_Training cdpl project nar
mdkazialamin16
 
Development of Software for Estimation of Structural Dynamic Characteristics ...
Development of Software for Estimation of Structural Dynamic Characteristics ...Development of Software for Estimation of Structural Dynamic Characteristics ...
Development of Software for Estimation of Structural Dynamic Characteristics ...
IRJET Journal
 
CAT-II Answer Key.pdf
CAT-II Answer Key.pdfCAT-II Answer Key.pdf
CAT-II Answer Key.pdf
Selvaraj Seerangan
 
Introduction to FreeRTOS
Introduction to FreeRTOSIntroduction to FreeRTOS
Introduction to FreeRTOS
ICS
 
Using Eclipse MQTT & Sparkplug as your IIoT Digital Transformation Toolkit | ...
Using Eclipse MQTT & Sparkplug as your IIoT Digital Transformation Toolkit | ...Using Eclipse MQTT & Sparkplug as your IIoT Digital Transformation Toolkit | ...
Using Eclipse MQTT & Sparkplug as your IIoT Digital Transformation Toolkit | ...
Eclipse IoT
 
IoT Seminar (Oct. 2016) Jong Young Lee - MDS Technology
IoT Seminar (Oct. 2016) Jong Young Lee - MDS TechnologyIoT Seminar (Oct. 2016) Jong Young Lee - MDS Technology
IoT Seminar (Oct. 2016) Jong Young Lee - MDS Technology
Open Mobile Alliance
 
Home automation using IoT and AWS Cloud technology
Home automation using IoT and AWS Cloud technologyHome automation using IoT and AWS Cloud technology
Home automation using IoT and AWS Cloud technology
ratthaslip ranokphanuwat
 
M.Tech Internet of Things Unit - III.pptx
M.Tech Internet of Things Unit - III.pptxM.Tech Internet of Things Unit - III.pptx
M.Tech Internet of Things Unit - III.pptx
AvinashAvuthu2
 
FPGA Implementation of Real Time Data Acquisition System Using Micro blaze Pr...
FPGA Implementation of Real Time Data Acquisition System Using Micro blaze Pr...FPGA Implementation of Real Time Data Acquisition System Using Micro blaze Pr...
FPGA Implementation of Real Time Data Acquisition System Using Micro blaze Pr...
Editor IJCATR
 
IRJET- Raspberry Pi and NodeMCU based Home Automation System
IRJET- Raspberry Pi and NodeMCU based Home Automation SystemIRJET- Raspberry Pi and NodeMCU based Home Automation System
IRJET- Raspberry Pi and NodeMCU based Home Automation System
IRJET Journal
 
174085193 pic-prgm-manual
174085193 pic-prgm-manual174085193 pic-prgm-manual
174085193 pic-prgm-manual
Arun Shan
 
NI Compact RIO Platform
NI Compact RIO PlatformNI Compact RIO Platform
NI Compact RIO Platform
jlai
 
Using raspberry pi to sense temperature and relative humidity
Using raspberry pi to sense temperature and relative humidityUsing raspberry pi to sense temperature and relative humidity
Using raspberry pi to sense temperature and relative humidity
IRJET Journal
 
Eclipse Edje: A Java API for Microcontrollers
Eclipse Edje: A Java API for MicrocontrollersEclipse Edje: A Java API for Microcontrollers
Eclipse Edje: A Java API for Microcontrollers
MicroEJ
 
20081114 Friday Food iLabt Bart Joris
20081114 Friday Food iLabt Bart Joris20081114 Friday Food iLabt Bart Joris
20081114 Friday Food iLabt Bart Joris
imec.archive
 
Industrial Hazard Monitoring using IOT
Industrial Hazard Monitoring using IOTIndustrial Hazard Monitoring using IOT
Industrial Hazard Monitoring using IOT
Ayush Chhangani
 
Android Things in action
Android Things in actionAndroid Things in action
Android Things in action
Stefano Sanna
 
Control System_Training cdpl project nar
Control System_Training cdpl project narControl System_Training cdpl project nar
Control System_Training cdpl project nar
mdkazialamin16
 
Development of Software for Estimation of Structural Dynamic Characteristics ...
Development of Software for Estimation of Structural Dynamic Characteristics ...Development of Software for Estimation of Structural Dynamic Characteristics ...
Development of Software for Estimation of Structural Dynamic Characteristics ...
IRJET Journal
 
Introduction to FreeRTOS
Introduction to FreeRTOSIntroduction to FreeRTOS
Introduction to FreeRTOS
ICS
 
Ad

Recently uploaded (20)

Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
Vaibhav Gupta BAML: AI work flows without Hallucinations
Vaibhav Gupta BAML: AI work flows without HallucinationsVaibhav Gupta BAML: AI work flows without Hallucinations
Vaibhav Gupta BAML: AI work flows without Hallucinations
john409870
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
TrsLabs Consultants - DeFi, WEb3, Token Listing
TrsLabs Consultants - DeFi, WEb3, Token ListingTrsLabs Consultants - DeFi, WEb3, Token Listing
TrsLabs Consultants - DeFi, WEb3, Token Listing
Trs Labs
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Build 3D Animated Safety Induction - Tech EHS
Build 3D Animated Safety Induction - Tech EHSBuild 3D Animated Safety Induction - Tech EHS
Build 3D Animated Safety Induction - Tech EHS
TECH EHS Solution
 
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdfAre Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Telecoms Supermarket
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
Vaibhav Gupta BAML: AI work flows without Hallucinations
Vaibhav Gupta BAML: AI work flows without HallucinationsVaibhav Gupta BAML: AI work flows without Hallucinations
Vaibhav Gupta BAML: AI work flows without Hallucinations
john409870
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
TrsLabs Consultants - DeFi, WEb3, Token Listing
TrsLabs Consultants - DeFi, WEb3, Token ListingTrsLabs Consultants - DeFi, WEb3, Token Listing
TrsLabs Consultants - DeFi, WEb3, Token Listing
Trs Labs
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Build 3D Animated Safety Induction - Tech EHS
Build 3D Animated Safety Induction - Tech EHSBuild 3D Animated Safety Induction - Tech EHS
Build 3D Animated Safety Induction - Tech EHS
TECH EHS Solution
 
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdfAre Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Telecoms Supermarket
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
Ad

Build a Java and Raspberry Pi weather station

  • 1. BUILD A JAVA WEATHER STATION USE YOUR RASPBERRY PI2 AND DEVELOP A WEB CLIENT
  • 2. MARCO PIRRUCCIO Research and Development Director, Partner @ Kettydo+ srl E-mail [email protected] LinkedIn www.linkedin.com/in/marcopirruccio
  • 4. HARDWARE SHOPPING LIST • Raspberry Pi2 • DHT22 (temperature, humidity) • BMP180 (temperature, pressure, altitude) • ML8511 (UV intensity) • TGS2600 (air contaminants) • MCP3800 (ADC for ML8511 and TGS2600) • A red and a green LED • A tactile button switch
  • 5. SOFTWARE INGREDIENTS On the Raspberry Pi • Java 8 • Pi4J and WiringPi • MQTT (Eclipse Paho Java client) On the web client • WebSockets (Eclipse Paho JavaScript client) • JavaScript: jQuery, HighCharts • HTML, CSS
  • 8. MQTT (MESSAGE QUEUING TELEMETRY TRANSPORT) • MQTT is a “machine-to-machine” (M2M) or “Internet of Things” (IoT) connectivity protocol. • It was designed as an extremely lightweight publish/subscribe messaging transport. • It was designed for constrained devices and low-bandwidth, high-latency or unreliable networks. • MQTT was invented by Dr Andy Stanford-Clark of IBM and Arlen Nipper of Arcom (now Eurotech) in 1999. • It is an application protocol over TCP/IP. • Quality of service levels: • 0: at most once delivery • 1: at least once delivery • 2: exactly once delivery (there is an increased overhead associated with this quality of service)
  • 9. WEBSOCKETS • The WebSockets specification was developed as part of the HTML5 initiative. • The WebSockets standard defines a full-duplex single socket connection over which messages can be sent between client and server. • WebSockets provide an enormous reduction in unnecessary network traffic and latency compared to the unscalable polling and long-polling solutions that were used to simulate a full-duplex connection by maintaining two connections.
  • 10. JAVA, PI4J, WIRINGPI • Raspbian includes the official Oracle Java 8 for ARM since the end of 2013. Older versions can install it using apt-get. • The Pi4J project is intended to provide a friendly object-oriented I/O API and implementation libraries for Java Programmers to access the full I/O capabilities of the Raspberry Pi platform. • It abstracts the low-level native integration and interrupt monitoring to enable Java programmers to focus on implementing their application business logic. • Main features: • Control, read and write GPIO pin states • Listen for GPIO pin state changes (interrupt-based; not polling) • I2C, SPI, RS232 communication • WiringPi is a GPIO access library written in C for the BCM2835.
  • 11. WEATHER STATION MAIN CLASS WeatherStationReader reader = new WeatherStationReader(); WeatherStationWriter writer = WeatherStationWriterFactory.getWriter(Writer.MQTT); Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { reader.shutdown(); writer.close(); } }); while (true) { WeatherStationData data = reader.read(); writer.write(data); Thread.sleep(2000); }
  • 12. WEATHER STATION READER: INITIALIZATION GpioController controller = GpioFactory.getInstance(); MCP3008 adc = new MCP3008(); ML8511 uv = new ML8511(adc, ML8511_ADC_CHANNEL); TGS2600 gas = new TGS2600(adc, TGS2600_ADC_CHANNEL); BMP180 bar = new BMP180(); DHT22 t = new DHT22(DHT22_PIN); GpioPinDigitalInput button = controller.provisionDigitalInputPin(BUTTON_GPIO, PinPullResistance.PULL_UP); button.addListener(new GpioPinListenerDigital() { public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) { System.exit(0); } }); ActivityNotifier an = new ActivityNotifier(READ_ACTIVITY_NOTIFIER_GPIO, "readerLed");
  • 13. WEATHER STATION READER: READING SENSORS an.notifyActivity(); WeatherStationData res = new WeatherStationData(); DHT22Response th = t.read(); res.setTemperature((float) th.getTemperature()); res.setHumidity((float) th.getHumidity()); gas.setReferenceHumidity(res.getHumidity()); gas.setReferenceTemperature(res.getTemperature()); TGS2600Response air = gas.read(); res.setAirQuality(air.getResistance()); res.setEthanol((int) air.getC2h5ohPPM()); res.setButane((int) air.getC4h10PPM()); res.setHydrogen((int) air.getH2PPM()); float uvIntensity = uv.read(); res.setUvIntensity(uvIntensity); final float pressure = bar.readPressure(); res.setPressure(pressure / 100);
  • 14. WEATHER STATION WRITER: INITIALIZATION String broker = "tcp://iot.eclipse.org:1883"; String clientId = WeatherStation.class.getName(); MemoryPersistence persistence = new MemoryPersistence(); MqttClient client = new MqttClient(broker, clientId, persistence); MqttConnectOptions connOpts = new MqttConnectOptions(); connOpts.setCleanSession(true); client.connect(connOpts); ActivityNotifier an = new ActivityNotifier(WRITE_ACTIVITY_NOTIFIER_GPIO, "writerLed");
  • 15. WEATHER STATION WRITER: SENDING DATA String topic = "/WeatherStation"; int qos = 2; String json = jsonSerializer.serialize(data); an.notifyActivity(); MqttMessage message = new MqttMessage(json.getBytes()); message.setQos(qos); client.publish(topic, message);
  • 16. THE WEB CLIENT: HTML MARKUP <div id="container-main"></div> <div> <div id="container-uv"></div> <div id="container-aq"></div> <div id="container-gas"> <table> <thead> <tr><td>PPM</td></tr> </thead> <tbody> <tr><td>Ethanol</td><td id="ethanol">0</td></tr> <tr><td>Butane</td><td id="butane">0</td></tr> <tr><td>Hydrogen</td><td id="hydrogen">0</td></tr> </tbody> </table> </div> </div>
  • 17. THE WEB CLIENT: WEBSOCKET var host = 'ws://iot.eclipse.org/ws'; var topic = '/WeatherStation'; var clientId = "WeatherStationClient"; var client = new Paho.MQTT.Client(host, clientId); client.onConnectionLost = function(responseObject) { ... }; client.onMessageArrived = function(message) { ... }; client.connect({ onSuccess : function() { client.subscribe(topic); } });
  • 18. THE WEB CLIENT: CHARTS client.onMessageArrived = function(message) { var data = JSON.parse(message.payloadString); var chart = $('#container-main').highcharts(); chart.series[0].addPoint([data.timestamp, data.temperature]); chart.series[1].addPoint([data.timestamp, data.humidity]); chart.series[2].addPoint([data.timestamp, data.pressure]); chart.redraw(); chart = $('#container-uv').highcharts(); var point = chart.series[0].points[0]; point.update(parseFloat(data.uvIntensity.toFixed(2))); chart = $('#container-aq').highcharts(); point = chart.series[0].points[0]; point.update(parseInt(data.airQuality.toFixed(0))); $('#ethanol').html(data.ethanol); $('#butane').html(data.butane); $('#hydrogen').html(data.hydrogen); };
  • 20. VIEW A LIVE DEMO AT BOOTH MAK 72
  • 21. REFERENCES • http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/mqtt-v3.1.1.html • https://eclipse.org/paho/clients/java/ • https://www.websocket.org/ • https://eclipse.org/paho/clients/js/ • http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html • http://pi4j.com/ • http://wiringpi.com/ • http://www.highcharts.com/