/// <summary> /// modifies the device 3d type to "delete" and sends it to MQTT /// also tries to delete the WorldAnchors /// </summary> /// <param name="baseAdress"></param> public void sendDeleteOrderForWorldAnchorAndAppData(AppData.uniqueIDDevice device) { device.DeviceType3D = "delete"; AppDataManager_MQTT.Instance.publishDeviceOverMQTT(device); //sends a device with the remove command to all active members in the network AppDataManager_MQTT.Instance.removeDeviceOverMQTT(device); //sends a remove command to clean up the server var anchorInfo = WorldAnchorAvailableOnlineManager.Instance.getAnchorAvailableOnline(device.baseAdress); if (!anchorInfo.Equals(default(KeyValuePair <string, DateTime>)))//if there is an anchor available { AppDataExportManager.Instance.MQTTPublishMessage(AppDataExportManager.Instance.worldAnchorBaseSubscriptionPath + TimeMethodesForAnchors.getAnchorNameWithTimeFromKeyValuePair(anchorInfo), "");//deletion order for retained messages AppDataExportManager.Instance.MQTTPublishMessage(WorldAnchorAvailableOnlineManager.Instance.worldAnchorStatusSubscriptionPath + TimeMethodesForAnchors.getAnchorNameWithTimeFromKeyValuePair(anchorInfo), "");//deletion order for retained messages } //deletes wa info from the prefs PlayerPrefs.DeleteKey(device.baseAdress); //now remove the device locally removeDeviceFromAppDataAndDeleteFromHierarchie(device.baseAdress); }
private void onAnchorAvailable(KeyValuePair <string, DateTime> anchor) { if (anchor.Equals(default(KeyValuePair <string, DateTime>))) { //no anchor has been found //fallback to any anchor from Store Debug.LogWarning("empty anchor given"); } else { //3. decide wether to load the new anchor online or keep from store //if anchor.value is earlier than latest anchor //or the anchor from the store does not exist //or anchor is on override if (anchor.Value > latestAnchor || !WorldAnchorManager.Instance.hasAnchorInStore(gameObject) || anchorOrigin == AnchorOrigin.OverrideAnchorFromServer) { //get the anchor from mqtt //we have the name and the time of the newest anchor //generate a topic and subscribe to it AppDataExportManager.Instance.subscribe( AppDataExportManager.Instance.worldAnchorBaseSubscriptionPath + TimeMethodesForAnchors.getAnchorNameWithTimeFromKeyValuePair(anchor), onAnchorDataAvailable); } } }
private void onExportCompletedForUnity(object transferbatch) { //anchor exported Debug.Log("Anchor Exported for: " + this.gameObject.name + ". now transmitting " + toExport.Count + " bytes"); AppDataExportManager.Instance.MQTTPublishAnchor(this.gameObject.name, toExport.ToArray()); latestAnchor = TimeMethodesForAnchors.getCurrentTimeforAnchors(); toExport = null;//free space }
private void onExportCompletedForUnity(object anchorDataObject, object o2) { var anchorData = (List <byte>)anchorDataObject; //anchor exported Debug.Log("Anchor Exported for: " + this.gameObject.name + ". now transmitting " + anchorData.Count + " bytes"); AppDataExportManager.Instance.MQTTPublishAnchor(this.gameObject.name, anchorData.ToArray()); latestAnchor = TimeMethodesForAnchors.getCurrentTimeforAnchors(); //toExport = null;//free space }
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> /// Only For Anchors. Time will be attached to the anchor string as well /// </summary> /// <param name="topic"></param> /// <param name="Anchor"></param> public void MQTTPublishAnchor(string topic, byte[] Anchor) { if (!client.isInitialized) { Start(); } //construct a good string that functions as topic topic = worldAnchorBaseSubscriptionPath + topic + "__" + TimeMethodesForAnchors.getCurrentTimeforAnchorAsString(); topic = topic.Replace("//", "/"); client.MQTTPublishMessage(topic, Anchor); }
/// <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); } }