Ejemplo n.º 1
0
        public void Destroy()
        {
            //Send to Logger Module a message saying tha module was destroyed
            Dictionary <string, string> thisIsMyProperty = new Dictionary <string, string>();

            thisIsMyProperty.Add("source", "IoTHubConnector");
            thisIsMyProperty.Add("type", "Log");
            GW.Message messageToPublish = new GW.Message("IoTHubConnector Module Destroyed.", thisIsMyProperty);
            this.broker.Publish(messageToPublish);
        }
Ejemplo n.º 2
0
        public void Receive(IoTGateway.Message received_message)
        {
            if (received_message.Properties.ContainsKey("Alstom.deviceID") && received_message.Properties.ContainsKey("Alstom.deviceKey"))
            //if (received_message.Properties["source"] == "Alstom.camera")
            {
                string curDeviceID       = received_message.Properties["Alstom.deviceID"];
                string curDeviceKey      = received_message.Properties["Alstom.deviceKey"];
                string curEventDeviceID  = received_message.Properties["deviceId"];
                string curEvent          = received_message.Properties["event"];
                string curEventTimestamp = received_message.Properties["time"];

                string message = @"{
                    'id': '" + curEventDeviceID + @"',
                    'deviceId': '" + curDeviceID + @"',
                    'alarm': 0,
                    'status': 1,
                    'eventName': '" + curEvent + @"',
                    'content': '',
                    'dateTime': '" + curEventTimestamp + @"'
                  }";

                var message2Send = new Message(Encoding.ASCII.GetBytes(message));

                switch (curDeviceID)
                {
                case "cam1":
                    deviceClient_cli1.SendEventAsync(message2Send);
                    break;

                case "cam2":
                    deviceClient_cli2.SendEventAsync(message2Send);
                    break;

                case "cam3":
                    deviceClient_cli3.SendEventAsync(message2Send);
                    break;

                default:
                    Console.WriteLine("IotTHub Module did not sent message from " + curDeviceID + ".");
                    break;
                }
                //deviceClient.CloseAsync();

                //Async
                //SendDeviceToCloudMessagesAsync(message2Send, curDeviceID);


                Console.WriteLine("IotTHub Module sent message from device " + curDeviceID + " : " + message);
            }
        }
        /// <summary>
        /// Wraps data nicely in json and publishes to the gateway broker
        /// </summary>
        /// <param name="TagName">Name of the tag</param>
        /// <param name="TagValue">Value of the tag</param>
        /// <param name="TagDateTime">Datetime of the observed value change</param>
        /// <param name="TagQuality">The reported quality of the value</param>
        public void PublishTag(string TagName, string TagValue, DateTime TagDateTime, string TagQuality)
        {
            // Wrap data nicely before releasing them to the broker
            messageWrap mw = new messageWrap();

            mw.content[0] = new sensorData(TagName, TagValue, TagDateTime.ToString("yyyy-MM-dd HH:mm:ss"), TagQuality);
            string json = "[" + JsonConvert.SerializeObject(mw, Formatting.None) + "]";

            Microsoft.Azure.IoT.Gateway.Message messageToPublish = new Microsoft.Azure.IoT.Gateway.Message(json, _messageProperties);

            // Publish to broker
            this._broker.Publish(messageToPublish);

            // If applicable - print to console window the message sent
            if (_config.PrintToConsole)
            {
                Console.WriteLine("Proficy.Historian.Module - sent: " + json);
            }
        }
 /// <summary>
 /// This function is for processing messages from the broker (Not implemented as this module is strictly a data source)
 /// </summary>
 /// <param name="received_message">The message to be processed</param>
 public void Receive(Microsoft.Azure.IoT.Gateway.Message received_message)
 {
     // Function must be implemented, but this module shouldn't process data - it is only a data source.
     // In future scenario, should be able to receive new list of tags to subscribe, and possibly also requests for batch exports.
 }
Ejemplo n.º 5
0
 public void Receive(GW.Message received_message)
 {
     //ToDo: Identify signal as device
     this.SendDeviceToCloudMessagesAsync(received_message.Content);
 }