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

How to connect Modbus device to Edgex Foundry? #178

Open
tnt310 opened this issue Oct 12, 2020 · 51 comments
Open

How to connect Modbus device to Edgex Foundry? #178

tnt310 opened this issue Oct 12, 2020 · 51 comments
Labels
question Further information is requested

Comments

@tnt310
Copy link

tnt310 commented Oct 12, 2020

Hi, I'm newbie in Edgex Foundry. I want to connect Modbus device( inverter Delta-vfd-l) to Device Service. I install Edgex Foundry on rasperry Pi 3 through sudo snap install edgexfoundry and Edgex UI showed at http://((your-raspberry-pir-url):4000/. I read lots of documents but all guide use Docker to deploy Edgex. How to connect Modbus device to Device Service not use Docker? Please help me

@cloudxxx8 cloudxxx8 added the question Further information is requested label Oct 12, 2020
@cloudxxx8
Copy link
Member

@tonyespy @anonymouse64 it's question about using snap. could you please help answer him? thanks.

@tnt310
Copy link
Author

tnt310 commented Oct 13, 2020

@tonyespy @anonymouse64 Please help me with EgdeX.

@tnt310
Copy link
Author

tnt310 commented Oct 13, 2020

@cloudxxx8 In case I use Docker and Docker-compose to connect real modbus device (Inverter) to EdgeX Foundry? Can you give me a document or link about this stuff, please? I use Rasperry Pi 3 and I installed Ubuntu 18.04.5 server on SD card.

@cloudxxx8
Copy link
Member

Here is a tutorial
https://docs.edgexfoundry.org/1.2/examples/Ch-ExamplesAddingModbusDevice/

@tnt310
Copy link
Author

tnt310 commented Oct 15, 2020

@cloudxxx8 I updated device profile but at Device Service not show edgex-device-modbus. what's wrong?
UI

@cloudxxx8
Copy link
Member

I am not sure whether it is an UI issue. Could you please try to call the REST API to see your Device Service?
http://host:48081/api/v1/deviceservice

https://app.swaggerhub.com/apis-docs/EdgeXFoundry1/core-metadata/1.2.0#/default/get_v1_deviceservice

@tnt310
Copy link
Author

tnt310 commented Oct 19, 2020

@cloudxxx8 I check device service then I know Modbus device service is Enable. But how can I check device connection in metadata and registered device in core data? Please help me !
image

@tnt310
Copy link
Author

tnt310 commented Oct 19, 2020

Ah,I check device through curl -s http://Rasperry-IP:48081/api/v1/device | jq then I know device modbus is not exist. So, maybe device is not registered in metadata. How can I check this?

@tnt310
Copy link
Author

tnt310 commented Oct 19, 2020

@cloudxxx8 I can use this comment????
image

@cloudxxx8
Copy link
Member

@trantram310 yes, please use POST API to create the Device. You have to create Device Profile first.
GUI service also calls this API to create a Device.

@tnt310
Copy link
Author

tnt310 commented Oct 19, 2020

@cloudxxx8 Ah, I updated Modbus Device profile successfully, but when I use POST API to create device that it's error ( error: invalid character 'A' looking for beginning of object key string)
I'm confused about Configuration.toml file cuz it dont explain about protocol.
image
image

@cloudxxx8
Copy link
Member

Configuration is for the service itself, and you should follow the JSON schema defined in the API to create the device
https://app.swaggerhub.com/apis-docs/EdgeXFoundry1/core-metadata/1.2.0#/default/post_v1_device

The Modbus example shows in the "Set Up After Starting Services" section step 3.
https://docs.edgexfoundry.org/1.2/examples/Ch-ExamplesAddingModbusDevice/

@tnt310
Copy link
Author

tnt310 commented Oct 20, 2020

@cloudxxx8 I read document you give and I use POST API with statement. But it not create Modbus device for me. I check device profile in metadata then metadata has device profile.
image

@tnt310
Copy link
Author

tnt310 commented Oct 20, 2020

@cloudxxx8 My code and error
image

@tnt310
Copy link
Author

tnt310 commented Oct 20, 2020

This is my Modbus device profile.
image

@cloudxxx8
Copy link
Member

it is a JSON format issue. please remove the comma in the last line of each {} block
for example,
"unitID":"1",

and

"profile":{"name":"Test-Device-Modbus"},

@tnt310
Copy link
Author

tnt310 commented Oct 20, 2020

@cloudxxx8 Maybe I miss DeviceID. So I fix 2 errors as you. It show Device ID and Name are both blank

@cloudxxx8
Copy link
Member

are you calling PUT or POST? You don't need to assign Id for POST

@tnt310
Copy link
Author

tnt310 commented Oct 20, 2020

@cloudxxx8 I call POST api.
image

@cloudxxx8
Copy link
Member

you have an additional space in the profile section

@tnt310
Copy link
Author

tnt310 commented Oct 20, 2020

@cloudxxx8 So, How can I check this error? Maybe in my device profile I put to metadata?

@tnt310
Copy link
Author

tnt310 commented Oct 20, 2020

This is my device profile.
image

@tnt310
Copy link
Author

tnt310 commented Oct 20, 2020

@cloudxxx8 I check addressable then:
image

@cloudxxx8
Copy link
Member

No, the addressable is for Device Service, not Device.
Your profile is fine.

The error message Device ID and Name are both blank is incorrect. It should say: Device Profile ID and Name are both blank

The problem is caused by your profile section in your Device creation:

"profile":{"name ": "Test-Device-Modbus"}

There is an additional space in "name ", so it says there is no name.

@tnt310
Copy link
Author

tnt310 commented Oct 20, 2020

@cloudxxx8 Yes, It returns me a ID. How can I get value from my Modbus device sensor. I use curl 192.168.1.22:48082/api/v1/device/{deviceId}/Lux , but it returns me 404 page not found

@cloudxxx8
Copy link
Member

if you use device id, you should also use command id.
instead, you can use device name and command name API
https://app.swaggerhub.com/apis-docs/EdgeXFoundry1/core-command/1.2.0#/default/get_v1_device_name__name__command__commandname_

@tnt310
Copy link
Author

tnt310 commented Oct 20, 2020

I check device command use curl 192.168.1.22:48082/api/v1/device | json_pp then know. How can i get sensor data from this?
image

@tnt310
Copy link
Author

tnt310 commented Oct 20, 2020

@cloudxxx8 I check device through curl 192.168.1.22:48081/api/v1/device | jq the know
image

@tnt310
Copy link
Author

tnt310 commented Oct 20, 2020

I check 192.168.1.22:48082/api/v1/device to get command then Modbus not get url.
image

@cloudxxx8
Copy link
Member

please paste the full result of 192.168.1.22:48082/api/v1/device in text

@tnt310
Copy link
Author

tnt310 commented Oct 20, 2020

Modbus..txt
It's little visionable !!!

@cloudxxx8
Copy link
Member

there are some URL fields in the result, and you should use them
Or, it is clear in the Execute GET command section of the document
192.168.1.22:48082/api/v1/device/name/Test-Device-Modbus/command/Lux

It is the API I mentioned

@tnt310
Copy link
Author

tnt310 commented Oct 20, 2020

@cloudxxx8 wait! I check 192.168.1.22:48082/api/v1/device and see it not show commands which I code in Modbus device profile. Is it real problems? This is all of about Modbus device when I check 192.168.1.22:48082/api/v1/device again.
image

@tnt310
Copy link
Author

tnt310 commented Oct 20, 2020

@cloudxxx8 When I use curl 192.168.1.22:48082/api/v1/device/6a29dc9b-c307-4f95-9b5e-4fed431ff6c9/Lux then it return me 404 page not found. it not have a lux value

@cloudxxx8
Copy link
Member

again, you hit thewrong API.
curl 192.168.1.22:48082/api/v1/device/6a29dc9b-c307-4f95-9b5e-4fed431ff6c9/Lux is wrong

Please see the API document. The API is not api/v1/device/{device id}/{command name}
it is
​/v1​/device​/{id}​/command​/{commandid}
or
/v1/device/name/{name}/command/{commandname}

I also notice that the command sections are wrong in your profile.

Please see the Set Up Device Profile section. You need to define deviceCommands and coreCommands
https://docs.edgexfoundry.org/1.2/examples/Ch-ExamplesAddingModbusDevice/

However, your profile contains resources and commands. Thus, there is no command in your Device can be called.

@tnt310
Copy link
Author

tnt310 commented Oct 21, 2020

@cloudxxx8 Yes, I do as you said about modbus device profile, I fix it and when I call curl 192.168.1.22:48082/api/v1/device then it return me commands. But when I call statements as command then it dont return me sensor data as I defined in device profile. It return me:
image
image

@tnt310
Copy link
Author

tnt310 commented Oct 21, 2020

@cloudxxx8 I check this commands and return me this errors.
image

@cloudxxx8
Copy link
Member

cloudxxx8 commented Oct 21, 2020

it's a permission issue. you should:

  1. chmod /dev/ttyUSB0 to give the proper permission
  2. add device mapping in the docker-compose file, and let the container can access it
    https://docs.docker.com/compose/compose-file/#devices

@tnt310
Copy link
Author

tnt310 commented Oct 21, 2020

@cloudxxx8 I'm deploying through Snap store, not docker-compose file. So, I can't know the second you said.

@tnt310
Copy link
Author

tnt310 commented Oct 21, 2020

@cloudxxx8 I fix and check again. It returns errors:
image

@cloudxxx8
Copy link
Member

You have connected to the Device with the wrong starting address.
Please confirm the deviceResources - attributes section is correct and match the Modbus Device.
Also, the data type should be correct
The starting address is 1 base, not 0 base.

For example from the document:

deviceResources:
  -
    name: "Current"
    description: "Average current of all phases"
    attributes:
      { primaryTable: "HOLDING_REGISTERS", startingAddress: "6" }
    properties:
      value:
        { type: "UINT16", scale: "1"}
      units:
        { type: "String", readWrite: "R", defaultValue: "min"}

@tnt310
Copy link
Author

tnt310 commented Oct 21, 2020

@cloudxxx8 I fix as you said. But it return me old error. This is my device document and deviceResources I defined.
image
image
And here is my Post API to create new device.
image

I dont know where is problem I meet ?

@tnt310
Copy link
Author

tnt310 commented Oct 21, 2020

@cloudxxx8 This is my full Device profile. Please help me find problem, I really need your help.
image

@cloudxxx8
Copy link
Member

The starting address is 1 base, so you can try
{ primaryTable: "HOLDING_REGISTERS", startingAddress: "7" }

@tnt310
Copy link
Author

tnt310 commented Oct 21, 2020

@cloudxxx8 It returns me old errors. But i dont know when I call this command then it return is that Device not found while I created it??
image

@tnt310
Copy link
Author

tnt310 commented Oct 22, 2020

@cloudxxx8 When I check port UART I use to read sensor data then I see.
image
I follow steps in document but it return me error.I dont know where is error?

@tnt310
Copy link
Author

tnt310 commented Oct 22, 2020

@cloudxxx8 I dont know here is my problem. I check file configuration.toml in /snap/edgex-device-modbus/1256/config/device-modbus/res then I see it not define [Devicelist]. Here is all in file configuration.toml in edgex-device-modbus packet I install through Snap
image
image

@cloudxxx8
Copy link
Member

please restart the modbus device service and try again

@tonyespy
Copy link
Member

A couple of comments...

  • Please use this issue for further discussion of your problem, as it's confusing when the discussion is happening in more than one place (i.e. this issue & slack).
  • Please confirm that your trying to use the device service in RTU mode (i.e. a serial device). If so, what is the actual hardware (i.e. not the Linux serial device) you're working with?
  • In an earlier comment, you were trying to add a device with Address=/dev/ttyUSB0. As the device-modbus snap is fully confined, AppArmor will prevent access to hardware interfaces by default. In fact, in the thread on #help, you posted output from dmesg which shows AppArmor denying access to the device service when it tries to open /dev/ttyUSB0. We haven't yet added support for the snap to securely access serial devices, so in order to use the snap for RTU Modbus, you need to install the snap using --devmode option. I'll work with my team to make sure this is documented. This is similar to what you'd need to do if you ran the device service via docker (i.e. you'd need to specify the container as privileged). I'll also add an issue to the device service to add support for secure access to serial devices for RTU mode.

@lingdujunshang
Copy link

@cloudxxx8 我更新了设备配置文件,但在设备服务中没有显示 edgex-device-modbus。怎么了? 用户界面
hello,i am develop neither docker nor snap, i have edgex-go and edgex-ui-go ready.but i just can not login ui page,i do not know how to get a token to login ..do u have any idea pls?

@cloudxxx8
Copy link
Member

please check the log of device-modbus container

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants