Edgexfoundry introduction

EdgeX Foundry is the Linux Foundation’s hardware – and os-neutral open source edge computing microservices framework for unifying the ecosystem of edge computing solutions for the Industrial Internet of Things.

Create device services using the SDK

Device-service created by ourselves can be modified on the basis of device-SDK-Go provided by Edgex officially.

The main purpose of creating a device service is to implement the ProtocolDriver interface. In this instance, it goes to the driver directory and implements the Initialize, HandleReadCommands, and HandleWriteCommands functions.

  • Initialize
Initialize(lc logger.LoggingClient, asyncCh chan<- *dsModels.AsyncValues, deviceCh chan<- []dsModels.DiscoveredDevice) error 
Copy the code

Lc should be a logging system, asynCh is a channel that we can upload to CoreData by giving asynCh the value we want to upload, and deviceCh should be used to automatically discover devices.

  • HandleReadCommands
func (s *SimpleDriver) HandleReadCommands(deviceName string, protocols map[string]contract.ProtocolProperties, reqs []dsModels.CommandRequest) (res []*dsModels.CommandValue, err error)
Copy the code

This function is called when the user sends a get command through core-command and behaves like a physical device sending a read command request.

  • HandleWriteCommands
func (s *SimpleDriver) HandleWriteCommands(deviceName string, protocols map[string]contract.ProtocolProperties, reqs []dsModels.CommandRequest,
	params []*dsModels.CommandValue) error {
Copy the code

The usage is basically the same as HandleRandomCommends. The parameters uploaded by post are placed in params.

This section describes the directory structure and configuration files

The directory structure is as follows:

  • The configuration. Toml is introduced

It is used to configure the address and port number of the Device service, register with the EdgeX service, and pre-define the device. If it is deployed on a server, you need to change Host in [Service] to the IP address of the server. [Registry], [Clients], [Device], and [Logging] do not need to be changed.

Find [[DeviceList]] this section is used to pre-define devices

Name is the Name of the Device you created

A Profile is the Profile used to create the Device, which is the value of name in profile.yml

[[devicelist. AutoEvents]] is used to automatically send Command requests, corresponding to profile.yml to call get Command, corresponding to SDK interface to call HandleReadCommand function

Frequency is the Frequency at which requests are sent

Resource is the data type that sends the request, corresponding to deviceResources in proflie.yml.

  • Profile. Yml is introduced

Profile.yml is used to define the data type of the Device and to send commands to the Device through core-command.

The relationship between deviceResources, deviceCommands and coreCommands:

The value in deviceResources is the type of data that defines the Device to upload to deviceService.

CoreComands defines the operations that the core service core-Command can perform on the device, including get and PUT.

DeviceCommands is the bridge between coreCommands and deviceResources. It defines which numeric types coreCommands operate on when operating devices.

The first line name corresponds to the name in DeviceList in configuration.toml, which is the name of the Profile.

In deviceResources, name: “SwitchButton” represents the name of a data type for this device

The following properties define the basic numeric types of the SwitchButton

Corecommands define two methods for core-command to operate on devices, one is read (GET) and one is write (PUT).

ExpectedValues in GET indicate the type of the value you want to read, which is the same as the name in the Name directory in deviceResources

ParameterNames in PUT specifies the type of the value of the passed parameter. It is also the same as the name in the Name directory in deviceResources

DeviceCommands connects deviceResources to coreCommands

Name is the same as the name in coreCommands

To define GET in coreCommands, you need to get; to define PUT, you need to define set.

DeviceResource Is the same as name in deviceResources

A Device can be generated and registered with core-metadata using the predefined Device and siml. yaml files in configuration. toml, or a Device can be manually registered with siml. yaml