March 2018
Beginner to intermediate
410 pages
10h 40m
English
Adding content to the XML response is not straightforward. We add each value, if available, as a child element. At the end, we close the root element:
if (this.lastLight.HasValue)
{
Response.Write("<Light value='");
Response.Write(ToString(this.lastLight.Value, 2));
Response.Write("' unit='%'/>");
}
if (this.lastMotion.HasValue)
{
Response.Write("<Motionvalue='");
Response.Write(this.lastMotion.Value ?
"true" : "false");
Response.Write("'/>");
}
Response.Write("</Momentary>");
}
Since the method is called from a synchronous resource, the response will be sent automatically. The GitHub project also contains the JSON method, which is implemented in the same manner and which returns the same type of JSON as in the MQTT ...
Read now
Unlock full access