brunch

361. IoT Greengrass설정법 이해

by Master Seo


IoT Greengrass에서 디바이스는 클라우드에 연결하지 않고도

로컬 네트워크와 안전하게 통신하고 메시지를 교환할 수 있습니다


0 green.png



생성 순서.

<1> Cloud9 접속하기. IoT 역할을 계정에 연결하기.

<2> IoT Greengrass 에서 그룹을 만듬.

<3> Greengress Core 시작하기

<4> IoT Device 생성 , 기기 등록

<5> 기기를 Greengrass group에 추가하기

<6> IoT 기기 정책 업데이트하기

<7> Greengrass Core 에 접속하기

<8> Subscription table 사용하기

<9> 배포

<10> Shadow service



<1> Cloud9 접속하기. IoT 역할을 계정에 연결하기.


URL을 통해 미리 만들어진 cloud9 접속

Welcome 옆 + 클릭 > New Terminal

1 cloud9.png


1.

$ env

ROLE 확인.

20 arn.png


2

형식)

$ aws greengrass associate-service-role-to-account --role-arn [YOUR SERVICE ROLE ARN] --region us-west-2


$ aws greengrass associate-service-role-to-account --role-arn arn:aws:iam::322191416637:role/qls-14032726-a9d5c90e58e096f1-IoTWSIoTServiceRole-3R9ZOPL63YG --region us-west-2


결과

{ "AssociatedAt": "2019-09-11T14:24:26Z" }


// IoT 역할을 계정에 연결했다.




<2> IoT Greengrass 에서 그룹을 만듬.


1.

Service > iot Greengrass

Create Group

10 greenglass.png


2

Use default create

20 default.png


3

group name :

traffic_controller


> Create Group and Core

30 create group and core.png



4

Download these resources as a tar.gz

40 download.png


5

Finish






<3> Greengress Core 시작하기


1

pc 에 다운 로드 받은 파일을 cloud9 ec2-user 에 끌어다 놓는다.


2

ec2-user 폴더에서 압축풀기

$ sudo su -

# cd /home/ec2-user/

$ tar zxvf f8302eb291-setup.tar.gz -C /greengrass/

certs/f8302eb291.cert.pem

certs/f8302eb291.private.key

certs/f8302eb291.public.key

config/config.json


3

greengrass 데몬 실행하기

$

cd /greengrass/ggc/core/

$

sudo ./greengrassd start

Setting up greengrass daemon

Validating hardlink/softlink protection

Waiting for up to 1m10s for Daemon to start


Greengrass successfully started with PID: 25232


[root@ip-192-168-128-125 core]# ps -ef |grep greengrassd

root 25232 1 0 13:31 pts/3 00:00:00 /greengrass/ggc/packages/1.10.0/bin/daemon -core-dir /greengrass/ggc/packages/1.10.0 -greengrassdPid 25229

root 25251 4092 0 13:31 pts/3 00:00:00 grep --color=auto greengrassd





<4> IoT Device 생성 , 기기 등록


1

Services > IoT core > Onboard > Onboard a device > Get start >

400 onboard.png


2

Llinux/OSX > Python


3

name :

traffic_light


4

Linux/OSX 클릭해 다운로드 한다. > Next Step

410 linux.png


5

다운로드 받은 zip파일 이름을 traffic_light_kit.zip 로 변경한다.


6

다운로드 받은 zip 파일을 Drag & Drop 으로 cloud9에 올리자.

ec2-user/greengrass-bootcamp/traffic_light/ 에 올리자.

20 cloud9.png



7

터미털에서

압축풀기

$ cd /home/ec2-user/greengrass-bootcamp/traffic_light

$ unzip traffic_light_kit.zip

$ chmod +x start.sh

$ sudo ./start.sh

200 traffic_light.png




8

Ctrl + C 로 중지하기


/////////////////////////////////////////////////////////////////


9

IOT Core 로 돌아기서

Onboard > Get Start > Linux > python > Name : motion_sensor

> download > 이름 변경 motion_sensor_kit.zip



10

cloud 9 에서

/home/ec2-user/greengrass-bootcamp/motion_sensor 에 Drag and Drop 으로 올려 압축 풀기.


11

cd /home/ec2-user/greengrass-bootcamp/motion_sensor

unzip motion_sensor_kit.zip


12

chmod +x start.sh

sudo ./start.sh


40 motion.png




<5> 기기를 Greengrass group에 추가하기


IoT Core > greengrass > group > traffc_controller > device > add device > selete an iot thing > 선택 > finish

500 selete.png


add device > selete an iot thing > 기기 A 선택 > finish

add device > selete an iot thing > 기기 B 선택 > finish




<6> IoT기기 정책 업데이트하기


1

device > traffice-light thing > security > cetificate > policies > traffice-light-policy > policy docment > edit policy document

정책 업데이트

xxxxxxxxxxxxxxxxxxxx

> Save a new version


600 save a new version.png


2.

Things > motion_sensor > security > certi policy > motion_sensor-policy > Edit policy doc

정책

xxxxxxxxxxxxxxxxxxxxxxxx

> Save as new version





<7> Greengrass core 에 접속하기


1.

cloud9 에서


wget https://s3-us-west-2.amazonaws.com/us-west-2-aws-training/awsu-spl/spl-240/1.0.3.prod/scripts/GGBootcampPubSubLight.py


GGBootcampPubSubLight.py



2

https://s3-us-west-2.amazonaws.com/us-west-2-aws-training/awsu-spl/spl-240/1.0.3.prod/scripts/GGBootcampPubSubSensor.py


GGBootcampPubSubSensor.py

// 추가 설정




<8> Subscription table 사용하기


Things > group > traffic_controller > subscrption > add subscrption >

Select a source : devices 텝 > traffic_light

Selete target : devices 탭 > motion_sensor

Topic Filter

sdk/test/Python

800 group.png



810 target.png
820.png



830 sdk.png


완료




<9> 배포



1

IoT Greengrass > group > xxxxxxx > 화면 오른쪽위 Action > Deploy > automatic detection 클릭


900 auto.png


2

cloud9 에서


cd ~/greengrass-bootcamp/motion_sensor/

sudo ./start.sh


cd ~/greengrass-bootcamp/traffic_light/

sudo ./start.sh




<10> shadow service

디바이스의 현재 상태 정보를 저장 및 검색하는 데 사용되는 JSON 문서입니다.


shadow섀도우를 사용하여 디바이스가 인터넷에 연결되어 있는지 여부와 상관없이 MQTT 또는 HTTP를 통해 디바이스의 상태를 가져오고 설정할 수 있습니다

https://docs.aws.amazon.com/ko_kr/iot/latest/developerguide/iot-device-shadows.html


1

iot core

greengrass group > traffic_controller >subscriptions > add subscription


2

select a source > device > motion_sensor

selete a target > service > iot cloud


next > topic filter > sdk/test/Python > Next > Finish


3

Action > deploy


1100.png


//////////////////


4

sercvice > iot Coce > Test > subcription to a topic : sdk/test/Python

1100.png


7

Green glass > group > traffice controller group > devices > traffic_light > sync to the cloud


8

Subscriptions > Add Subscriptions > select a source > device > traffic_light

selete a target > service > Local shadow service

topic filter >

$aws/things/traffic_light/shadow/#

> finish



9

Add Subscription

selete a source > serives > local shadow service

selete a traget > device > traffic_light

Next

topic filter >

$aws/things/traffic_light/shadow/#

> next > finish



10

Add Subscription

selete a source > device > traffic_light

selete a target > serives > Iot Cloud

topic filter >

sdk/test/Python

> next > finish



11

Action

Deploy



12

IoT core

Test

Subscription topic

sdk/test/Python



감사합니다.




1. IoT 참고 자료


https://docs.aws.amazon.com/ko_kr/greengrass/latest/developerguide/what-is-gg.html


209. AWS IoT 시작 하기 https://brunch.co.kr/@topasvga/845

359. IoT 시작하기 https://brunch.co.kr/@topasvga/1146

360. IoT 테스트 해보기 https://brunch.co.kr/@topasvga/1147

361. IoT Greengrass https://brunch.co.kr/@topasvga/1149




keyword
매거진의 이전글360. IoT Application 배포법 이해