Example #1
0
        public void onMqttMessage(string topic, string message, DateTime timestamp)
        {
            getLogger().LogDebug("Sensor '{0}' received MQTT message. topic='{1}', message='{2}', timestamp='{3}'", Id, topic, message, timestamp.ToString());
            getTriggeredFromString(message);


            //Log Raw data to database
            ZoneGuardConfigContextFactory factory = new ZoneGuardConfigContextFactory();

            using (ZoneGuardConfigContext context = factory.CreateDbContext())
            {
                SensorStateRawLogDAL rawLog = new SensorStateRawLogDAL();
                rawLog.SensorName     = Id;
                rawLog.State          = message;
                rawLog.SensorType     = sensorType;
                rawLog.AdditionalInfo = topicState;

                rawLog.Timestamp = DateTime.UtcNow;

                context.RawSensorStateLog.Add(rawLog);
                context.SaveChanges();
            }


            SensorStateMessage msg = new SensorStateMessage(Id, getTriggeredFromString(message), timestamp);

            getManager().PublishSensorState(msg);
        }
Example #2
0
        void callbackStateMessageHandler(object sender, BasicDeliverEventArgs eventArgs)
        {
            var body    = eventArgs.Body;
            var message = Encoding.UTF8.GetString(body);

            Console.WriteLine(" State Message Arrived: {0}", message);
            SensorStateMessage ssm    = MessageCore.fromJSON <SensorStateMessage>(message);
            SensorCore         sensor = getSensorByName(ssm.Id);

            ((SensorProxy)sensor).setTriggeredState(ssm.Triggered);
        }
Example #3
0
 public void PublishSensorState(SensorStateMessage ssm)
 {
     ServiceMQ.Publish(ServiceMQ.EXCHANGE_STATE, "", ssm.toJSON());
 }