private static void SendAppMessage(Pebble pebble) { string uuidAppPath = SelectApp(); if (!string.IsNullOrEmpty(uuidAppPath) && File.Exists(uuidAppPath)) { using (var stream = new FileStream(uuidAppPath, FileMode.Open)) { using (var zip = new Zip()) { zip.Open(stream); var bundle = new AppBundle(); stream.Position = 0; bundle.Load(zip, pebble.Firmware.HardwarePlatform.GetSoftwarePlatform()); System.Console.Write("Enter Message:"); var messageText = System.Console.ReadLine(); //format a message var rand = new Random().Next(); AppMessagePacket message = new AppMessagePacket(); message.Command = (byte)Command.Push; message.Values.Add(new AppMessageUInt32() { Key = 0, Value = (uint)rand }); message.Values.Add(new AppMessageString() { Key = 1, Value = messageText }); message.ApplicationId = bundle.AppMetadata.UUID; message.TransactionId = 255; //send it Console.WriteLine("Sending Status " + rand + " to " + bundle.AppMetadata.UUID.ToString()); var task = pebble.SendApplicationMessage(message); task.Wait(); Console.WriteLine("Response received"); } } } else { Console.WriteLine("No .pbw"); } }
private static async Task ShowPebbleMenu(Pebble pebble) { //string uuid = "22a27b9a-0b07-47af-ad87-b2c29305bab6"; var menu = new Menu( "Disconnect", "Get Time", "Set Current Time", "Get Firmware Info", "Send Ping", "Media Commands", "Install App", "Send App Message", "Reset", "Send Notification"); while (true) { switch (menu.ShowMenu()) { case 0: pebble.Disconnect(); return; case 1: var timeResult = await pebble.GetTimeAsync(); DisplayResult(timeResult, x => string.Format("Pebble Time: " + x.Time.ToString("G"))); break; case 2: await pebble.SetTimeAsync(DateTime.Now); goto case 1; case 3: var firmwareResult = await pebble.GetFirmwareVersionAsync(); DisplayResult(firmwareResult, x => string.Join(Environment.NewLine, "Firmware", x.Firmware.ToString(), "Recovery Firmware", x.RecoveryFirmware.ToString())); break; case 4: var pingResult = await pebble.PingAsync(); DisplayResult(pingResult, x => "Received Ping Response"); break; case 5: ShowMediaCommands(pebble); break; case 6: var progress = new Progress <ProgressValue>( pv => Console.WriteLine(pv.ProgressPercentage + " " + pv.Message)); string appPath = SelectApp(); if (!string.IsNullOrEmpty(appPath) && File.Exists(appPath)) { using (var stream = new FileStream(appPath, FileMode.Open)) { using (var zip = new Zip()) { zip.Open(stream); var bundle = new AppBundle(); stream.Position = 0; bundle.Load(zip, pebble.Firmware.HardwarePlatform.GetPlatform()); var task = pebble.InstallClient.InstallAppAsync(bundle, progress); await task; if (task.IsFaulted) { Console.WriteLine("Failed to install"); } //for firmware v3, launch is done as part of the install //Console.WriteLine("App Installed, launching..."); //var uuid=new UUID(bundle.AppInfo.UUID); //pebble.LaunchApp(uuid); //Console.WriteLine ("Launched"); } } } else { Console.WriteLine("No .pbw"); } break; case 7: //read the uuid from the pbw string uuidAppPath = SelectApp(); if (!string.IsNullOrEmpty(uuidAppPath) && File.Exists(uuidAppPath)) { using (var stream = new FileStream(uuidAppPath, FileMode.Open)) { using (var zip = new Zip()) { zip.Open(stream); var bundle = new AppBundle(); stream.Position = 0; bundle.Load(zip, pebble.Firmware.HardwarePlatform.GetPlatform()); //format a message var rand = new Random().Next(); AppMessagePacket message = new AppMessagePacket(); message.Values.Add(new AppMessageUInt32() { Value = (uint)rand }); message.Values.Add(new AppMessageString() { Value = "Hello from .net" }); message.ApplicationId = bundle.AppMetadata.UUID; message.TransactionId = 255; //send it Console.WriteLine("Sending Status " + rand + " to " + bundle.AppMetadata.UUID.ToString()); var t = pebble.SendApplicationMessage(message); await t; Console.WriteLine("Response received"); } } } else { Console.WriteLine("No .pbw"); } break; case 8: pebble.Reset(ResetCommand.Reset); break; case 9: TestNotification(pebble); break; } } }