Expected Behavior
On my edge device I have a tempSensor module routing into a filter function module. The Function simply copies every incoming message into its output. I expect to get exactly the same messages out of the function as are coming out of the temp sensor. This is an example message coming out of tempSensor module directly (using VS Code to monitor):
[IoTHubMonitor] Message received from [andre-desktop]:
{
"machine": {
"temperature": 31.844796382051335,
"pressure": 2.2354831321324307
},
"ambient": {
"temperature": 20.745613186268887,
"humidity": 24
},
"timeCreated": "2018-07-27T22:59:15.1345698Z"
}
Current Behavior
After going through the Function, I get malformed messages (see this screenshot):
![fromfunction](https://user-images.githubusercontent.com/10746890/43350309-faab7d6e-91ba-11e8-84cd-966c2cee28cf.jpg)
Steps to Reproduce
I'm following steps in this tutorial: https://docs.microsoft.com/en-us/azure/iot-edge/tutorial-deploy-function
Except I don't make any modifications to the function code which is generated by the template. Here is my function code:
#r "Microsoft.Azure.Devices.Client"
using System.IO;
using Microsoft.Azure.Devices.Client;
public static async Task Run(Message messageReceived, IAsyncCollector output, TraceWriter log)
{
byte[] messageBytes = messageReceived.GetBytes();
var messageString = System.Text.Encoding.UTF8.GetString(messageBytes);
if (!string.IsNullOrEmpty(messageString))
{
log.Info("Info: Received one non-empty message");
var pipeMessage = new Message(messageBytes);
foreach (KeyValuePair<string, string> prop in messageReceived.Properties)
{
pipeMessage.Properties.Add(prop.Key, prop.Value);
}
await output.AddAsync(pipeMessage);
log.Info("Info: Piped out the message");
}
}
Here is my deployment template:
{
"moduleContent": {
"$edgeAgent": {
"properties.desired": {
"schemaVersion": "1.0",
"runtime": {
"type": "docker",
"settings": {
"minDockerVersion": "v1.25",
"loggingOptions": "",
"registryCredentials": {
"andretestcr": {
"username": "$CONTAINER_REGISTRY_USERNAME_andretestcr",
"password": "$CONTAINER_REGISTRY_PASSWORD_andretestcr",
"address": "andretestcr.azurecr.io"
}
}
}
},
"systemModules": {
"edgeAgent": {
"type": "docker",
"settings": {
"image": "mcr.microsoft.com/azureiotedge-agent:1.0",
"createOptions": ""
}
},
"edgeHub": {
"type": "docker",
"status": "running",
"restartPolicy": "always",
"settings": {
"image": "mcr.microsoft.com/azureiotedge-hub:1.0",
"createOptions": "{"HostConfig":{"PortBindings":{"8883/tcp":[{"HostPort":"8883"}],"443/tcp":[{"HostPort":"443"}]}}}"
}
}
},
"modules": {
"tempSensor": {
"version": "1.0",
"type": "docker",
"status": "running",
"restartPolicy": "always",
"settings": {
"image": "mcr.microsoft.com/azureiotedge-simulated-temperature-sensor:1.0",
"createOptions": ""
}
},
"SampleFunc": {
"version": "1.0",
"type": "docker",
"status": "running",
"restartPolicy": "always",
"settings": {
"image": "${MODULES.SampleFunc.amd64.debug}",
"createOptions": ""
}
}
}
}
},
"$edgeHub": {
"properties.desired": {
"schemaVersion": "1.0",
"routes": {
"sensorToSampleFunc": "FROM /messages/modules/tempSensor/outputs/temperatureOutput INTO BrokeredEndpoint("/modules/SampleFunc/inputs/input1")",
"SampleFuncToIoTHub": "FROM /messages/modules/SampleFunc/* INTO $upstream"
},
"storeAndForwardConfiguration": {
"timeToLiveSecs": 7200
}
}
}
}
}
I made 2 modifications in this deployment template:
- I'm using a .debug image for the function
- I modified the route SampleFuncToIoTHub to be "FROM /messages/modules/SampleFunc/* INTO $upstream" instead of "FROM /messages/modules/SampleFunc/outputs/output1 INTO $upstream". Without this change, the messages from function output weren't going to IoT Hub.
Context (Environment)
Device (Host) Operating System
Windows 10 Ent
Architecture
x64
Container Operating System
Linux containers
Runtime Versions
GA
iotedged
iotedge 1.0.0 (52ef77d)
Edge Agent
mcr.microsoft.com/azureiotedge-agent:1.0
Edge Hub
mcr.microsoft.com/azureiotedge-hub:1.0
Docker
Client:
Version: 18.06.0-ce
API version: 1.38
Go version: go1.10.3
Git commit: 0ffa825
Built: Wed Jul 18 19:05:28 2018
OS/Arch: windows/amd64
Experimental: false
Server:
Engine:
Version: 18.06.0-ce
API version: 1.38 (minimum version 1.12)
Go version: go1.10.3
Git commit: 0ffa825
Built: Wed Jul 18 19:13:46 2018
OS/Arch: linux/amd64
Experimental: true
Logs
I didn't notice anything suspicious in the logs. Here is a short snippet of edgeHub log:
2018-07-27 22:43:18.986 +00:00 [DBG] [Microsoft.Azure.Devices.Edge.Hub.Amqp.LinkHandlers.EventsLinkHandler] - EventsLinkHandler processed 1 messages for andre-desktop/tempSensor
2018-07-27 22:43:18.986 +00:00 [DBG] [Microsoft.Azure.Devices.Edge.Hub.Core.Storage.MessageStore] - Getting next batch for endpoint andre-desktop/SampleFunc/input1 starting from 24 with batch size 10.
2018-07-27 22:43:18.988 +00:00 [DBG] [Microsoft.Azure.Devices.Edge.Hub.Core.Storage.MessageStore] - Obtained next batch for endpoint andre-desktop/SampleFunc/input1 with batch size 1. Next start offset = 25.
2018-07-27 22:43:18.988 +00:00 [DBG] [Microsoft.Azure.Devices.Edge.Hub.Core.Routing.ModuleEndpoint] - Sending 1 message(s) to module andre-desktop/SampleFunc.
2018-07-27 22:43:18.989 +00:00 [DBG] [Microsoft.Azure.Devices.Edge.Hub.Core.Device.DeviceMessageHandler] - Sent message with correlation ID db986baa-5432-4b69-846d-c871c88782d0 to andre-desktop/SampleFunc
2018-07-27 22:43:18.989 +00:00 [DBG] [Microsoft.Azure.Devices.Edge.Hub.Amqp.LinkHandlers.SendingLinkHandler] - Sent message with id db986baa-5432-4b69-846d-c871c88782d0 to device andre-desktop/SampleFunc
2018-07-27 22:43:18.993 +00:00 [DBG] [Microsoft.Azure.Devices.Edge.Hub.Amqp.LinkHandlers.EventsLinkHandler] - EventsLinkHandler processed 1 messages for andre-desktop/SampleFunc
2018-07-27 22:43:18.993 +00:00 [DBG] [Microsoft.Azure.Devices.Edge.Hub.Core.Storage.MessageStore] - Getting next batch for endpoint iothub starting from 6 with batch size 10.
2018-07-27 22:43:18.994 +00:00 [DBG] [Microsoft.Azure.Devices.Edge.Hub.Core.Storage.MessageStore] - Obtained next batch for endpoint iothub with batch size 1. Next start offset = 7.
2018-07-27 22:43:18.994 +00:00 [DBG] [Microsoft.Azure.Devices.Edge.Hub.Core.Routing.CloudEndpoint] - Sending 1 message(s) upstream.
2018-07-27 22:43:19.002 +00:00 [DBG] [Microsoft.Azure.Devices.Edge.Hub.Core.Device.DeviceMessageHandler] - Received feedback Complete for message db986baa-5432-4b69-846d-c871c88782d0 from device/module andre-desktop/SampleFunc
2018-07-27 22:43:19.003 +00:00 [DBG] [Microsoft.Azure.Devices.Edge.Hub.Core.Storage.MessageStore] - Getting next batch for endpoint andre-desktop/SampleFunc/input1 starting from 25 with batch size 10.
2018-07-27 22:43:19.003 +00:00 [DBG] [Microsoft.Azure.Devices.Edge.Hub.Core.Storage.MessageStore] - Obtained next batch for endpoint andre-desktop/SampleFunc/input1 with batch size 0. Next start offset = 25.
2018-07-27 22:43:19.019 +00:00 [DBG] [Microsoft.Azure.Devices.Edge.Hub.CloudProxy.DeviceConnectivityManager] - IotHub call succeeded
2018-07-27 22:43:19.019 +00:00 [DBG] [Microsoft.Azure.Devices.Edge.Hub.CloudProxy.ConnectivityAwareClient] - Operation SendEventAsync succeeded
2018-07-27 22:43:19.019 +00:00 [DBG] [Microsoft.Azure.Devices.Edge.Hub.CloudProxy.CloudProxy] - Sending message for device andre-desktop/SampleFunc
2018-07-27 22:43:19.019 +00:00 [DBG] [Microsoft.Azure.Devices.Edge.Hub.Core.Storage.MessageStore] - Getting next batch for endpoint iothub starting from 7 with batch size 10.
2018-07-27 22:43:19.019 +00:00 [DBG] [Microsoft.Azure.Devices.Edge.Hub.Core.Storage.MessageStore] - Obtained next batch for endpoint iothub with batch size 0. Next start offset = 7.
2018-07-27 22:43:23.987 +00:00 [DBG] [Microsoft.Azure.Devices.Edge.Hub.Amqp.LinkHandlers.EventsLinkHandler] - EventsLinkHandler processed 1 messages for andre-desktop/tempSensor
Additional Information