Beispiel #1
0
        private void CreateAndPublishMessage(string topic, string payload)
        {
            var fields = topic.Split('/', StringSplitOptions.RemoveEmptyEntries);

            if (fields.Length < 6)
            {
                throw new ArgumentException("Topic does not seem to be a valid topic");
            }

            var nodeId      = Int32.Parse(fields[1]);
            var sensorId    = Int32.Parse(fields[2]);
            var messageType = (MessageType)Int32.Parse(fields[3]);
            var ack         = fields[4] == "1";

            if (messageType == MessageType.C_SET || messageType == MessageType.C_REQ)
            {
                var type           = Int32.Parse(fields[5]);
                var sensorDataType = (SensorDataType)type;
                var message        = new MySensorsDataMessage(nodeId, sensorId, sensorDataType, ack, payload);
                queueProvider.EnqueueMessage(message);
            }
            else if (messageType == MessageType.C_PRESENTATION)
            {
                var sensorType = (SensorType)Int32.Parse(fields[5]);
                var message    = new MySensorsPresentationMessage(nodeId, sensorId, sensorType, ack, payload);
                //TODO: Not sure what to do with these...
            }
        }
        public void PutResidentStatus()
        {
            var user     = User.Identity.Name;
            var messsage = new ResidentStatusEvent()
            {
                Status = ResidentsStatus.GoingToSleep
            };

            queue.EnqueueMessage(messsage);
        }