Skip to content
This repository has been archived by the owner on Oct 12, 2023. It is now read-only.

Commit

Permalink
[Update] update doc, format, code
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephen Chen committed Nov 15, 2017
1 parent 5d2d778 commit f708329
Show file tree
Hide file tree
Showing 12 changed files with 226 additions and 139 deletions.
20 changes: 20 additions & 0 deletions Docker/linux-arm32/Dockerfile-auto
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM microsoft/dotnet:sdk AS build-env
WORKDIR /app

# copy csproj and restore as distinct layers
COPY src/*.cs* ./
RUN dotnet restore

# copy everything else and build
RUN dotnet build
RUN dotnet publish -f netcoreapp2.0 -c Release -o out

FROM microsoft/dotnet:2.0.0-runtime-stretch-arm32v7

ARG EXE_DIR=.

WORKDIR /app

COPY --from=build-env /app/out ./

CMD ["/usr/bin/dotnet", "iot-edge-modbus.dll"]
9 changes: 2 additions & 7 deletions Docker/linux-x64/Dockerfile-auto
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,11 @@ FROM microsoft/dotnet:sdk AS build-env
WORKDIR /app

# copy csproj and restore as distinct layers
COPY . ./
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
RUN echo "deb http://download.mono-project.com/repo/ubuntu xenial main" | tee /etc/apt/sources.list.d/mono-official.list
RUN apt-get update
RUN apt-get --yes --force-yes install mono-devel
RUN mono NuGet.exe sources Add -Name "Edge Private Preview" -source https://www.myget.org/F/aziot-device-sdk/api/v3/index.json
RUN mono NuGet.exe list -source https://www.myget.org/F/aziot-device-sdk/api/v3/index.json
COPY src/*.cs* ./
RUN dotnet restore

# copy everything else and build
RUN dotnet build
RUN dotnet publish -f netcoreapp2.0 -c Release -o out

FROM microsoft/dotnet:2.0.0-runtime
Expand Down
2 changes: 1 addition & 1 deletion Docker/windows-nano/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ WORKDIR /app

COPY $EXE_DIR/ ./

CMD ["dotnet", "iot-edge-modbus.dll"]
CMD ["/usr/bin/dotnet", "iot-edge-modbus.dll"]
20 changes: 20 additions & 0 deletions Docker/windows-nano/Dockerfile-auto
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM microsoft/dotnet:sdk AS build-env
WORKDIR /app

# copy csproj and restore as distinct layers
COPY src/*.cs* ./
RUN dotnet restore

# copy everything else and build
RUN dotnet build
RUN dotnet publish -f netcoreapp2.0 -c Release -o out

FROM microsoft/dotnet:2.0.0-runtime-nanoserver-1709

ARG EXE_DIR=.

WORKDIR /app

COPY --from=build-env /app/out ./

CMD ["/usr/bin/dotnet", "iot-edge-modbus.dll"]
14 changes: 14 additions & 0 deletions License.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Microsoft Azure IoT Edge Modbus
Copyright (c) Microsoft Corporation

MIT license
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the Software), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ This project has adopted the [Microsoft Open Source Code of Conduct](https://ope

# Azure IoT Edge Modbus Module Preview #
Using this module, developers can build Azure IoT Edge solutions with Modbus TCP connectivity. The Modbus module is an [Azure IoT Edge](https://github.com/Azure/iot-edge) module, capable of reading data from Modbus devices and publishing data to the Azure IoT Hub via the Edge framework. Developers can modify the module tailoring to any scenario.
![](./doc/diagram.png)
![](./doc/diagram.png)
If you are using V1 version of IoT Edge (previously known as Azure IoT Gateway), please use V1 version of this module, all materials can be found in [V1](https://github.com/Azure/iot-gateway-modbus/tree/master/V1) folder.

Visit http://azure.com/iotdev to learn more about developing applications for Azure IoT.
Expand All @@ -11,35 +11,37 @@ Visit http://azure.com/iotdev to learn more about developing applications for Az
Current version of the module is targeted for the Azure IoT Edge 1.0 preview version.

## Operating System Compatibility ##
Refer to [Azure IoT Edge](https://github.com/Azure/azure-iot-edge#operating-system-compatibility)
Refer to [Azure IoT Edge](https://github.com/Azure/azure-iot-edge)

## Hardware Compatibility ##
Refer to [Azure IoT Edge](https://github.com/Azure/azure-iot-edge#hardware-compatibility)
Refer to [Azure IoT Edge](https://github.com/Azure/azure-iot-edge)

## HowTo Run ##
This section will help you download the module from docker hub, and run it with IoT Edge directly.
1. Setup [Azure IoT Edge](https://github.com/Azure/azure-iot-edge#setup) with compatible version on your machine.
2. Follow [this](https://review.docs.microsoft.com/en-us/azure/iot-edge/tutorial-install-iot-edge?branch=release-iot-edge-v2#start-the-iot-edge-runtime) to deploy a custom IoT Edge module.
1. Setup [Azure IoT Edge](https://github.com/Azure/azure-iot-edge) with compatible version on your machine.
2. Follow [this](https://docs.microsoft.com/en-us/azure/iot-edge/quickstart?branch=release-iot-edge-v2) to deploy a custom IoT Edge module.
3. In the Image field, enter **microsoft/azureiotedge-modbus-tcp:1.0-preview**.
4. You may also want to provide configuration to the module when it starts, paste the configuration in the desired property field. For more about configuration, see [here](https://github.com/Azure/iot-gateway-modbus#configuration).
4. You may also want to provide configuration to the module when it starts, paste the configuration in the desired property field. For more about configuration, see [here](https://github.com/Azure/iot-edge-modbus#configuration).

## HowTo Build ##
If you prefer to build your own module, use the following script. Dockerfiles are located under [Docker](https://github.com/Azure/iot-gateway-modbus/tree/master/V1) folder, you should be able to find one for your platform.
1. dotnet add package Microsoft.Azure.Devices.Client -v 1.5.1-preview-003 -s https://www.myget.org/F/aziot-device-sdk/api/v3/index.json
If you prefer to build your own module, use the following script. Dockerfiles are located under [Docker](https://github.com/Azure/iot-edge-modbus/tree/master/Docker) folder, you should be able to find one for your platform. There are two Docker files in each platform, the one ended with **-auto** will automatically build source code and Docker image. The other one requires you to build source code first and then copy binary to the image.
### -auto ###
docker build -t "**name of the docker image**" -f "**path to the auto docker file**".
### non-auto ###
1. cd src/
2. dotnet restore
3. dotnet build
4. dotnet publish -f netcoreapp2.0
5. docker build --build-arg EXE_DIR=./bin/Debug/netcoreapp2.0/publish -t "**name of the docker image**" -f "**path to the docker file**".

## Configuration ##
The Modbus module uses module twin as its configuration.
Here is a sample configuration for your reference.
The Modbus module uses module twin as its configuration. Here is a sample configuration for your reference.
```json
{
"Interval": "1500",
"SlaveConfigs": {
"Slave01": {
"SlaveConnection": "192.168.0.1",
"Interval": "1500",
"HwId": "PowerMeter-0a:01:01:01:01:01",
"Operations": {
"Op01": {
Expand All @@ -58,7 +60,6 @@ Here is a sample configuration for your reference.
},
"Slave02": {
"SlaveConnection": "192.168.0.2",
"Interval": "1500",
"HwId": "PowerMeter-0a:01:01:01:01:02",
"Operations": {
"Op01": {
Expand All @@ -81,8 +82,8 @@ Here is a sample configuration for your reference.
Meaning of each field:

* "SlaveConfigs" – Contains one or more Modbus slaves' configuration. In this sample, we have Slave01 and Slave02 two devices:
* "Interval" – Interval between each push to IoT Hub in millisecond
* "SlaveConnection" – IPV4 address of the Modbus slave
* "Interval" – Interval between each read operation (not implement yet)
* "HwId" – Unique Id for each Modbus slave (user defined)
* "Operations" – Contains one or more Modbus read requests. In this sample, we have Op01 and Op02 two read requests in both Slave01 and Slave02:
* "UnitId" – The unit id to be read
Expand Down Expand Up @@ -124,5 +125,4 @@ The command should have a property "command-type" with value "ModbusWrite". Also
```

## Debug ##
There is a flag **IOT_EDGE** at the first line in Program.cs, which can be turn off to debug the Modbus module in console mode. Note: running in console mode means none of the IoT Edge features is available.
This mode is only to debug non edge-related functions.
There is a flag **IOT_EDGE** at the first line in Program.cs, which can be turn off to debug the Modbus module in console mode. Note: running in console mode means none of the IoT Edge features is available. This mode is only to debug non edge-related functions. Running console mode requires IoT device connection string being inserted as a environment variable named **EdgeHubConnectionString**, and a local configuration file **iot-edge-modbus.json** since module twin is not available.
8 changes: 4 additions & 4 deletions edgeConfiguration.json → deployment.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"edgeAgent": {
"type": "docker",
"settings": {
"image": "edgepreview.azurecr.io/azureiotedge/edge-agent:1.0-preview",
"image": "microsoft/azureiotedge-agent:1.0-preview",
"createOptions": ""
}
},
Expand All @@ -23,7 +23,7 @@
"status": "running",
"restartPolicy": "always",
"settings": {
"image": "edgepreview.azurecr.io/azureiotedge/edge-hub:1.0-preview",
"image": "microsoft/azureiotedge-hub:1.0-preview",
"createOptions": ""
}
}
Expand All @@ -35,7 +35,7 @@
"status": "running",
"restartPolicy": "always",
"settings": {
"image": "<dockeruser>/<image>:<tag>",
"image": "microsoft/azureiotedge-modbus-tcp:1.0-preview",
"createOptions": "{}"
}
}
Expand All @@ -49,7 +49,7 @@
"route": "FROM /* INTO $upstream"
},
"storeAndForwardConfiguration": {
"timeToLiveSecs": 10
"timeToLiveSecs": 7200
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion iot-edge-modbus-template.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"Interval": "push interval in millisecond",
"SlaveConfigs": {
"Slave01": {
"SlaveConnection": "ipv4 address to Modbus device",
"Interval": "read interval",
"HwId": "unique HW Id defined by user",
"Operations": {
"Op01": {
Expand Down
3 changes: 1 addition & 2 deletions iot-edge-modbus.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"Interval": "1500",
"SlaveConfigs": {
"Slave01": {
"SlaveConnection": "127.0.0.1",
"Interval": "1500",
"HwId": "PowerMeter-0a:01:01:01:01:01",
"Operations": {
"Op01": {
Expand All @@ -21,7 +21,6 @@
},
"Slave02": {
"SlaveConnection": "127.0.0.1",
"Interval": "1500",
"HwId": "PowerMeter-0a:01:01:01:01:02",
"Operations": {
"Op01": {
Expand Down
Loading

0 comments on commit f708329

Please sign in to comment.