public async Task sendAppMessage(ExpandoObject data) { PebbleConnector _pc = PebbleConnector.GetInstance(); int newToken = await _pc.Connect(-1); try { if (_pc.IsConnected) { System.Diagnostics.Debug.WriteLine(String.Format("sendAppMessage(data={0})", data.ToString())); P3bble.Messages.AppMessage _am = new P3bble.Messages.AppMessage(P3bble.Constants.Endpoint.ApplicationMessage); uint iKey = 0; _am.Content = new Dictionary <int, object>(data.Count()); _am.Command = P3bble.Messages.AppCommand.Push; _am.AppUuid = ParentItem.ID; _am.TransactionId = (byte)_pc.GetNextMessageIdentifier(); foreach (var element in data) { if (element.Value != null) { if (ParentItem.AppKeys.ContainsKey(element.Key)) { iKey = (uint)ParentItem.AppKeys[element.Key]; Type VariableType = element.Value.GetType(); System.Diagnostics.Debug.WriteLine(String.Format(" key: {0}-{3}, value: {1}, type: {2}", element.Key, element.Value, VariableType.ToString(), iKey)); if (VariableType == typeof(String)) { String Value = (String)element.Value; //_am.AddTuple(iKey, P3bble.Messages.AppMessageTupleDataType.String, System.Text.Encoding.UTF8.GetBytes(Value)); _am.Content.Add((int)iKey, Value); } if (VariableType == typeof(Double)) { double dValue = (double)element.Value; int iValue = (int)dValue; byte[] bytes = BitConverter.GetBytes(iValue); //_am.AddTuple(iKey, P3bble.Messages.AppMessageTupleDataType.Int, bytes); _am.Content.Add((int)iKey, iValue); } } } } //byte[] package = _am.ToBuffer(); //System.Diagnostics.Debug.WriteLine("<< PAYLOAD: " + BitConverter.ToString(package).Replace("-", ":")); await _pc.Pebble._protocol.WriteMessage(_am); } } catch (Exception exp) { System.Diagnostics.Debug.WriteLine(exp.Message); } finally { _pc.Disconnect(newToken); } }