soracom beam から aws iot へのデータ送信

9

Upload: motokatsu-matsui

Post on 15-Apr-2017

1.040 views

Category:

Technology


3 download

TRANSCRIPT

Page 1: SORACOM Beam から AWS IoT へのデータ送信
Page 2: SORACOM Beam から AWS IoT へのデータ送信
Page 3: SORACOM Beam から AWS IoT へのデータ送信
Page 4: SORACOM Beam から AWS IoT へのデータ送信
Page 5: SORACOM Beam から AWS IoT へのデータ送信
Page 6: SORACOM Beam から AWS IoT へのデータ送信
Page 7: SORACOM Beam から AWS IoT へのデータ送信

# コピペ用コマンド# AWS IoTaws iot create-thing --thing-name raspi2aws iot create-keys-and-certificate --set-as-active |tee cert.json

certificateArn=$(jq -r .certificateArn < cert.json)jq -r .certificatePem < cert.json | tee cert.pemjq -r .keyPair.PrivateKey < cert.json | tee key.pem

aws iot create-policy --policy-name "PubSubToAnyTopic" --policy-document '{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Action":["iot:*"],"Resource":["*"]}]}'

aws iot attach-principal-policy --principal $certificateArn --policy-name "PubSubToAnyTopic"aws iot attach-thing-principal --thing-name raspi2 --principal $certificateArn

curl -o ca.pem https://www.symantec.com/content/en/us/enterprise/verisign/roots/VeriSign-Class%203-Public-Primary-Certification-Authority-G5.pem

cat rule.json{ "ruleDisabled": false, "sql": "SELECT * FROM 'beam2iot'", "description": "publish message to SNS", "actions": [ { "sns": { "targetArn": "arn:aws:sns:ap-northeast-1:903921708000:beam2iot", "roleArn": "arn:aws:iam::903921708000:role/aws_iot_sns" } } ]}aws iot create-topic-rule --rule-name beam2iot --topic-rule-payload file://rule.json

Page 8: SORACOM Beam から AWS IoT へのデータ送信

# Beamsoracom group create --tags name:AWSIoT | tee group.jsongroup_id=$(jq -r .groupId < group.json)

curl -O https://gist.githubusercontent.com/j3tm0t0/ba69a1a6f7af3b976c64/raw/b29a19347c08a7e06bb1c6ff3a20c822c8e1d572/Beam_to_AWSIoT.rbruby Beam_to_AWSIoT.rb key.pem cert.pem ca.pem $group_id

imsi=001010000000000soracom sim set_group --imsi $imsi --group-id $group_id

# on Raspberry Picat random.sh#!/bin/bashwait=$1if [ "$wait" = "" ]then

wait=5fiwhile [ 1 ]do timestamp=$(date +%s)cat <<EOF{"id":$RANDOM,"timestamp":$timestamp,"a":$RANDOM,"b":$RANDOM,"c":$RANDOM}EOF

sleep $waitdone

./random.sh | mosquitto_pub -d -h beam.soracom.io -t topic –l

# on Macwhile [ 1 ] ; do aws sqs receive-message --queue-url https://sqs.ap-northeast-1.amazonaws.com/000000000000/beam2iot --wait-time-seconds 20 | jq -r '.Messages[].Body' | jq -r .Message ; sleep 1 ; done

Page 9: SORACOM Beam から AWS IoT へのデータ送信