Skip to content

Commit

Permalink
Add deserializing reset command as JSON object to Sensor Simulator (#153
Browse files Browse the repository at this point in the history
)
  • Loading branch information
varunpuranik authored Aug 15, 2018
1 parent 7f1559c commit bf5f374
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions edge-modules/SimulatedTemperatureSensor/src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ ITransportSettings[] GetTransportSettings()
return moduleClient;
}

//Control Message expected to be:
// Control Message expected to be:
// {
// "command" : "reset"
// }
Expand All @@ -117,6 +117,7 @@ static Task<MessageResponse> ControlMessageHandle(Message message, object userCo
try
{
var messages = JsonConvert.DeserializeObject<ControlCommand[]>(messageString);

foreach (ControlCommand messageBody in messages)
{
if (messageBody.Command == ControlCommandEnum.Reset)
Expand All @@ -126,10 +127,24 @@ static Task<MessageResponse> ControlMessageHandle(Message message, object userCo
}
else
{
//NoOp
// NoOp
}
}
}
catch (JsonSerializationException)
{
var messageBody = JsonConvert.DeserializeObject<ControlCommand>(messageString);

if (messageBody.Command == ControlCommandEnum.Reset)
{
Console.WriteLine("Resetting temperature sensor..");
Reset.Set(true);
}
else
{
// NoOp
}
}
catch (Exception ex)
{
Console.WriteLine($"Failed to deserialize control command with exception: [{ex.Message}]");
Expand Down

0 comments on commit bf5f374

Please sign in to comment.