private void appDataReceived(MqttNetClientAccess.mqttMessage message) { if (message.payload.Length == 0) { Debug.Log("AppDatamanager_MQTT received a device whith payload length 0"); return; //this is a deletion message } string decodedMessage = System.Text.Encoding.UTF8.GetString(message.payload); AppData.uniqueIDDevice device = null; try { device = JsonConvert.DeserializeObject <AppData.uniqueIDDevice>(decodedMessage); } catch { Debug.Log("AppDatamanager_MQTT could not deserialize device " + message.topic); } //if device was not encoded if (device == null || string.IsNullOrEmpty(device.baseAdress)) { return; } //tell others invokeOnAppDataReceived?.Invoke(device); }
private void messageReceived(MqttNetClientAccess.mqttMessage mqttMsg) { //now we have a message to analyze //we may not invoke direktly, because we (the possibility exists) modify the invovationListForTopic as a reason of invoking. We need another list List <KeyValuePair <string, UnityAction <MqttNetClientAccess.mqttMessage> > > toInvoke = new List <KeyValuePair <string, UnityAction <MqttNetClientAccess.mqttMessage> > >(); foreach (KeyValuePair <string, UnityAction <MqttNetClientAccess.mqttMessage> > invokationElement in invocationListForTopic) { string invokation_topic = invokationElement.Key; if (invokation_topic.EndsWith("#")) { invokation_topic = invokation_topic.Remove(invokation_topic.Length - 1); // removes last char } //for all messages, that start with the invokation term. pass the message to the subscriber and invoke if (mqttMsg.topic.StartsWith(invokation_topic)) { toInvoke.Add(invokationElement); } } //now we can invoke foreach (KeyValuePair <string, UnityAction <MqttNetClientAccess.mqttMessage> > invokationElement in toInvoke) { invokationElement.Value.Invoke(mqttMsg); } }
private void onAnchorDataAvailable(MqttNetClientAccess.mqttMessage message) { DateTime anchorTime = TimeMethodesForAnchors.parseAnchor(message.topic).Value; importInformation = new ImportInformation(3, message.payload, anchorTime); //TODO: what happens when one anchor gets available while the other is currently importing //then we should somehow stop the import of the other and use the new //we have the anchor now AppDataExportManager.Instance.unsubscribe(message.topic, onAnchorDataAvailable); WorldAnchorTransferBatch.ImportAsync(message.payload, onImportComplete); }
private void onAnchorDataAvailable(MqttNetClientAccess.mqttMessage message) { DateTime anchorTime = TimeMethodesForAnchors.parseAnchor(message.topic).Value; //we have the anchor now AppDataExportManager.Instance.unsubscribe(message.topic, onAnchorDataAvailable); //importInformation = new ImportInformation(3, message.payload, anchorTime); //TODO: what happens when one anchor gets available while the other is currently importing //then we should somehow stop the import of the other and use the new //this will start a new import process and kills the old if there is one currentImportProcess = new WorldAnchorImport(message.payload, importetAnchorFromWorldAnchorImport, anchorTime, 3); }
/// <summary> /// new anchor status will bee added trough here /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void addWorldAnchorStatus(MqttNetClientAccess.mqttMessage message) { KeyValuePair <string, DateTime> newAnchorParsed = default(KeyValuePair <string, DateTime>); string[] tpcPth = null; string tpcPath_last = null; try { tpcPth = message.topic.Split('/'); //splits the topic path segments tpcPath_last = tpcPth[tpcPth.Length - 1]; //gets the last segment (name of the anchor with timestamp) Debug.Log("received message, added: " + tpcPath_last); newAnchorParsed = TimeMethodesForAnchors.parseAnchor(tpcPath_last); } catch { Debug.LogError("could not parse anchor: " + tpcPath_last); return; } if (message.payload.Length == 0) { return; //only valid messages get processed } //if there is already an anchor, remove it if (anchorsAvailableOnMqtt.ContainsKey(newAnchorParsed.Key)) //anchorsAvailableOnMqtt[newAnchorParsed.Key] < newAnchorParsed.Value) { if (anchorsAvailableOnMqtt[newAnchorParsed.Key] >= newAnchorParsed.Value) { return;//only lets newer anchors come into the list. older anchors gets dropped } anchorsAvailableOnMqtt.Remove(newAnchorParsed.Key); } //adds the anchor to the available anchors anchorsAvailableOnMqtt.Add(newAnchorParsed.Key, newAnchorParsed.Value); //now check if someone wants to be notified if (newAnchorAvailableDic.ContainsKey(newAnchorParsed.Key)) { newAnchorAvailableDic[newAnchorParsed.Key].Invoke(newAnchorParsed); } }