-
Notifications
You must be signed in to change notification settings - Fork 1
Sensor complete
using System.Threading.Tasks;
using XSockets.Core.XSocket;
using XSockets.Core.XSocket.Helpers;
public class TempModel
{
/// <summary>
/// Object temperature
/// </summary>
public double obj { get; set; }
/// <summary>
/// Ambient temperature
/// </summary>
public double amb { get; set; }
}
/// <summary>
/// Controller that sensor clients will use
/// </summary>
public class Sensor : XSocketController
{
/// <summary>
/// The name of the sensor
/// Should be set from the sensor when it is connected
/// </summary>
public string Name { get; set; }
/// <summary>
/// Last known value for this sensor
/// </summary>
public TempModel LastValue { get; set; }
public Sensor()
{
this.Name = "N/A - Waiting for sensor input";
this.LastValue = new TempModel();
}
/// <summary>
/// A sensor connected, tell all monitoring clients about it.
/// </summary>
public override Task OnOpened()
{
var objToSend = new {id = this.ConnectionId, this.LastValue.obj, this.LastValue.amb, name = this.Name};
this.InvokeToAll<Monitor>(objToSend, "sensorConnected");
return base.OnOpened();
}
/// <summary>
/// A sensor disconnected, tell all the monitoring clients about it.
/// </summary>
public override Task OnClosed()
{
this.InvokeToAll<Monitor>(this.ConnectionId, "sensorDisconnected");
return base.OnClosed();
}
/// <summary>
/// Will send the infomation to clients on the monitor controller that has templimit set to a value lower than obj/amb
/// </summary>
/// <param name="model"></param>
public void IrTempChange(TempModel model)
{
//set last know value so that new monitoring clients can get the information
this.LastValue = model;
var objToSend = new {id = this.ConnectionId, model.obj, model.amb, name = Name};
//Send only the clients mathching the expression
this.InvokeTo<Monitor>(p => p.TempLimit <= model.obj || p.TempLimit <= model.amb, objToSend,"irtempchange");
}
/// <summary>
/// Tell all monitoring client that IR-temp was enabled for this sensor
/// </summary>
public void IrTempEnabled()
{
this.InvokeToAll<Monitor>(this.ConnectionId, "irtempenabled");
}
/// <summary>
/// Tell all monitoring client that IR-temp was disabled for this sensor
/// </summary>
public void IrTempDisabled()
{
this.InvokeToAll<Monitor>(this.ConnectionId, "irTempDisabled");
}
}
Home
##Pre-Req
Software
Hardware
##Protocols
XMPP
AMQP
MQTT
WebSockets
Custom
##Raspberry Pi
Connecting
Configuration
WiFi
Update
###BLE
About
Support
GAP
Broadcast Topology
Connected Topology
GATT
Install
Configure
Connect
Read/Write
###NODEJS
Install
Install
Test
##XSockets
###Hosting
Self-hosted
Configuration
Azure worker role
###Let's build a location based chat
Chat controller
Add name & location
Target specific clients
Install
Test
###Sensor Controller
Basic
Adding state
Broadcast to all
Target specific clients
Confirm enable/disable
Complete
###Monitor Controller
Basic
OnOpened
Adding state
Turn sensor on/off
Complete
###Testing With Putty
Custom protocol
Connecting
Impersonate sensor
Impersonate monitor
###Scale Out
Azure Service Bus
##Suggested Clients
Overview
Web JavaScript
Putty
C-Sharp
TCP-IP
###MQTT
client
publish
##Azure
Hosting & scaling
##Links/Resources
Adafruit
Wikipedia