Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A new example executed by python program #107

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,307 changes: 1,307 additions & 0 deletions Photosensitive detection/cloudcore.log

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions Photosensitive detection/crds/deviceinstance.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: devices.kubeedge.io/v1alpha2
kind: Device
metadata:
name: light
labels:
description: 'light'
manufacturer: 'test'
spec:
deviceModelRef:
name: light-model
nodeSelector:
nodeSelectorTerms:
- matchExpressions:
- key: ''
operator: In
values:
- pi32-1
status:
twins:
- propertyName: light-status
desired:
metadata:
type: string
value: ''
13 changes: 13 additions & 0 deletions Photosensitive detection/crds/devicemodel.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: devices.kubeedge.io/v1alpha2
kind: DeviceModel
metadata:
name: light-model
namespace: default
spec:
properties:
- name: light-status
description: Light collected from the edge device
type:
string:
accessMode: ReadOnly
defaultValue: ''
49 changes: 49 additions & 0 deletions Photosensitive detection/light-mapper/light.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/python
# encoding:utf-8
import json
import sys
import os
import paho.mqtt.client as mqtt
import time


import RPi.GPIO as GPIO
import time



TASK_TOPIC = "$hw/events/device/" + "light" + "/twin/update"

client_id = time.strftime('%Y%m%d%H%M%S', time.localtime(time.time()))

client = mqtt.Client(client_id, transport='tcp')

client.connect("192.168.1.204", 1883, 60)
client.loop_start()


def clicent_main(message: str):

time_now = time.strftime('%Y-%m-%d %H-%M-%S', time.localtime(time.time()))
payload = {"event_id":"","timestamp":0,"twin":{"light-status":{"actual": {"value": "%s"%message}, "metadata": {"type":"Updated"}}}}

client.publish(TASK_TOPIC, json.dumps(payload, ensure_ascii=False))

return True

pin_pqrs=24
GPIO.setmode(GPIO.BCM)
GPIO.setup(pin_pqrs, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
try:
while True:
status = GPIO.input(pin_pqrs)
if status == False:
print('1')
clicent_main('light')
else:
print('0')
clicent_main('no_light')
time.sleep(0.5)
except KeyboradInterrupt:
GPIO.cleanup()

26 changes: 26 additions & 0 deletions Photosensitive detection/lightdeployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: light-mapper
labels:
app: light
spec:
replicas: 1
selector:
matchLabels:
app: light
template:
metadata:
labels:
app: light
spec:
hostNetwork: true
nodeSelector:
name: pi32-1
containers:
- name: light
image: yangrl/light-py:dev
imagePullPolicy: IfNotPresent
command: ["python3","-u", "/light.py"]
securityContext:
privileged: true
1 change: 1 addition & 0 deletions lightsensor-demo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@