边缘Kubeedge DHT11温湿度获取

本文介绍了如何基于kubeedge的temperature-demo和traffic-light例子,修改并实现在边缘节点raspberry pi 3B上通过DHT11传感器获取温湿度数据。内容包括修改CRDs文件、设备模型、mapper代码、生成镜像、部署配置以及查看结果的过程。
摘要由CSDN通过智能技术生成

基于kubeedge examples temperature-demo,并参考traffic-light例程,实现边缘kubeedge DHT11温湿度同时获取。

1 修改crds model.yaml和instance.yaml

model.yaml

kind: DeviceModel
metadata:
  name: temp-rh-model
  namespace: default
spec:
  properties:
    - name: temperature-status
      description: Temperature collected from the edge device
      type:
        string:
          accessMode: ReadOnly
          defaultValue: ''
    - name: humidity-status
      description: Relative humidity collected from the edge device
      type:
        string:
          accessMode: ReadOnly
          defaultValue: ''

instance.yaml

apiVersion: devices.kubeedge.io/v1alpha2
kind: Device
metadata:
  name: temp-rh
  labels:
    description: 'temp-rh'
    manufacturer: 'test'
spec:
  deviceModelRef:
    name: temp-rh-model
  nodeSelector:
    nodeSelectorTerms:
      - matchExpressions:
          - key: ''
            operator: In
            values:
              - calrbpi1
status:
  twins:
    - propertyName: temperature-status
      desired:
        metadata:
          type: string
        value: ''
    - propertyName: humidity-status
      desired:
        metadata:
          type: string
        value: ''

注:calrbpi1是我的部署edgenode,,修改为自己的。

2 Cloud端应用设备模型与设备

$ kubectl apply -f model.yaml
$ sed -i "s#edge-node#<your-edge-node-name>#g" instance.yaml
$ kubectl apply -f instance.yaml

3 修改temperature-mapper/main.go

cp -r temperature-mapper temp-rh-mapper
vim temp-rh-mapper/main.go
package main

import (
        "context"
        "encoding/json"
        "fmt"
        "os"
        "strconv"
        "syscall"
        "time"

        "github.com/d2r2/go-dht"
        "github.com/d2r2/go-shell"

        "github.com/yosssi/gmq/mqtt"
        "github.com/yosssi/gmq/mqtt/client"

        logger "github.com/d2r2/go-logger"
)

const (
        DEVICE_ID            = "temp-rh"
        TEMPERATURE_STATE    = "temperature-status"
        HUMIDITY_STATE       = "humidity-status"
)

var lg = logger.NewPackageLogger("main",
        logger.DebugLevel,
        // logger.InfoLevel,
)

//DeviceStateUpdate is the structure used in updating the device state
type DeviceStateUpdate struct {
        State string `json:"state,omitempty"`
}

//BaseMessage the base struct of event message
type BaseMessage struct {
        EventID   string `json:"event_id
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值