Pi4J + Amazon S3 REST API + Amazon Athena [P019]
https://www.youtube.com/watch?v=G-Ot7oh4_jk
GitHub : https://github.com/rdiot/rdiot-p019.git
* Parts
- Raspberry Pi2
- Temperature and humidity DHT11 sensor module (KY-015) [S008]
* Contents
- Connect
S - Signal GPIO3
middle - VCC
- - GND
1. Getting sensor value by Pi4J (Java I/O library for the Raspberry Pi) and then upload to amazon s3.
: Run the java application
$ java -Dpi4j.linking=dynamic -jar pi4j_s3rest-0.0.1-SNAPSHOT.jar
2. Check the upload status in the amazon console. (s3)
3. Setup Amazon Athena .
- add database : pisensor
- add table : temperature
- DDL (add table)
CREATE EXTERNAL TABLE IF NOT EXISTS piSensor.temperature (
`name` string,
`value` float
)
ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe'
WITH SERDEPROPERTIES (
'serialization.format' = '1'
) LOCATION 's3://rdkim-test/'
TBLPROPERTIES ('has_encrypted_data'='false');
4. SQL Query in the Amazon Athena
example : SELECT * FROM "pisensor"."temperature" limit 10;
- Pi4J Java Maven
<dependency>
<groupId>com.pi4j</groupId>
<artifactId>pi4j-core</artifactId>
<version>1.1</version>
</dependency>
- project maven pom.xml
: https://github.com/rdiot/rdiot-p019/blob/master/pom.xml
- source : main : https://github.com/rdiot/rdiot-p019/blob/master/pi4j_s3rest/App.java
- source : pi4j : https://github.com/rdiot/rdiot-p019/blob/master/pi4j/dht11.java
- source : s3 rest api header aws sig4 : https://github.com/rdiot/rdiot-p019/blob/master/s3rest/auth/AWS4SignerForAuthorizationHeader.java
- Key Code
dht11 dht = new dht11();
for (int i=0; i<10; i++) {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
objectContent = dht.getTemperature();
if(objectContent != null) {
System.out.println(objectContent);
putS3Object(bucketName, regionName, awsAccessKey, awsSecretKey);
break;
}
}
- Reference
: Pi4J Project : http://pi4j.com
: Pi4J GitHub : https://github.com/Pi4J/pi4j
: get dht11 : https://stackoverflow.com/questions/28486159/read-temperature-from-dht11-using-pi4j
: Amazon S3 Rest API : https://docs.aws.amazon.com/AmazonS3/latest/API/Welcome.html
'5) IoT_DataPlatform > Amazon AWS' 카테고리의 다른 글
S3 Lambda Trigger + Amazon SQS + SQSReceiver + SparkStreaming [P023] (0) | 2018.10.17 |
---|---|
Pi4J + Amazon S3 REST API + S3 Lambda Trigger + DynamoDB [P022] (0) | 2018.06.17 |
AWS IoT Core + Raspberry Pi + AWS IoT Device SDK for Java [P021] (0) | 2018.06.15 |
Amazon Polly + Google Home + Sonoff wifi [P018] (0) | 2018.04.04 |
Amazon Polly TTS(Text to Speech) [P017] (0) | 2018.03.30 |