public HistoryItem(DateTime stamp, LsMqtt mqtt) { Schedule sc = mqtt.Cfg.Schedule; Battery bt = mqtt.Dat.Battery; Statistic st = mqtt.Dat.Statistic; Local = true; Stamp = stamp; Error = mqtt.Dat.Error.ToString(); State = mqtt.Dat.State.ToString(); CfgMain += string.Format("tm:\u00A0{0} ", mqtt.Cfg.Time); CfgMain += string.Format("dt:\u00A0{0} ", mqtt.Cfg.Date); CfgMain += string.Format("rd:\u00A0{0} ", mqtt.Cfg.RainDelay); CfgPlan += string.Format("m:\u00A0{0} ", sc.Mode); CfgPlan += string.Format("p:\u00A0{0} ", sc.Perc); CfgPlan += "d:\r\n"; for (int i = 0; i < 7; i++) { CfgPlan += string.Format("{0}\u00A0{1}\u00A0{2}", sc.Days[i][0], sc.Days[i][1], sc.Days[i][2]); if (i < 6) { CfgPlan += ", "; } } CfgZone = string.Format("mz:\u00A0{0} ", string.Join(",", mqtt.Cfg.MultiZones)); CfgZone += string.Format("mzv:\u00A0{0}", string.Join(",", mqtt.Cfg.MultiZonePercs)); DatMain = string.Format("fw:\u00A0{0} ", mqtt.Dat.Firmware); DatMain += string.Format("ls:\u00A0{0} ", (int)mqtt.Dat.State); DatMain += string.Format("le:\u00A0{0} ", (int)mqtt.Dat.Error); DatMain += string.Format("lz:\u00A0{0} ", mqtt.Dat.LastZone); DatMain += string.Format("lk:\u00A0{0} ", mqtt.Dat.Lock); DatMain += string.Format("rsi:\u00A0{0}", mqtt.Dat.RecvSignal); DatAccu = string.Format("t:\u00A0{0} ", bt.Temp); DatAccu += string.Format("v:\u00A0{0} ", bt.Volt); DatAccu += string.Format("p:\u00A0{0} ", bt.Perc); DatAccu += string.Format("n:\u00A0{0} ", bt.Cycle); DatAccu += string.Format("c:\u00A0{0} ", (int)bt.Charging); DatAccu += string.Format("m:\u00A0{0}", bt.Mode); DatDmp = string.Format("dmp: {0}", string.Join(" ", mqtt.Dat.Orient)); DatStat = string.Format("b:\u00A0{0} ", st.Blade); DatStat += string.Format("d:\u00A0{0} ", st.Distance); DatStat += string.Format("wt:\u00A0{0}", st.WorkTime); StartTime = new string[7]; Duration = new string[7]; for (int i = 0; i < 7; i++) { StartTime[i] = sc.Days[i][0].ToString(); Duration[i] = string.Format("{0} {1}", sc.Days[i][1], sc.Days[i][2]); } }
private void Recv(object sender, MyEventArgs e) { LsMqtt mqtt = e.Mqtt; string dts = string.Format("{0} {1}", mqtt.Cfg.Date, mqtt.Cfg.Time); //Invoke(new MqttDelegate(RecvInvoke)); Mower.Name = App.Web.Products[0].Name; Mower.State = Resource.ResourceManager.GetString("STATE_" + mqtt.Dat.State.ToString()); if (mqtt.Dat.Error == ErrorCode.NONE) { Mower.Error = string.Empty; } else { Mower.Error = Resource.ResourceManager.GetString("ERROR_" + mqtt.Dat.Error.ToString()); } try { Mower.Rrsi = mqtt.Dat.RecvSignal; if (Math.Abs(Mower.Rrsi) < 50) { Mower.Wifi = "Wifi_Green.png"; } else if (Math.Abs(Mower.Rrsi) < 60) { Mower.Wifi = "Wifi_Blue.png"; } else if (Math.Abs(Mower.Rrsi) < 70) { Mower.Wifi = "Wifi_Yellow.png"; } else { Mower.Wifi = "Wifi_Red.png"; } } catch (Exception ex) { Trace.TraceError("WiFi =>" + ex); } Mower.Firmware = mqtt.Dat.Firmware; Mower.StartPoint = (mqtt.Cfg.MultiZonePercs[mqtt.Dat.LastZone] + 1).ToString(); Mower.Accu = mqtt.Dat.Battery; Mower.Pitch = mqtt.Dat.Orient[0]; Mower.Roll = mqtt.Dat.Orient[1]; Mower.Yaw = mqtt.Dat.Orient[2]; Mower.WorkTime = TimeSpan.FromMinutes(mqtt.Dat.Statistic.WorkTime); Mower.BladeTime = TimeSpan.FromMinutes(mqtt.Dat.Statistic.Blade); Mower.Distance = mqtt.Dat.Statistic.Distance; Mower.Stamp = DateTime.ParseExact(dts, "dd/MM/yyyy HH:mm:ss", CultureInfo.InvariantCulture); OnPropertyChanged(nameof(Mower)); if (DateTime.Now - lastWeather > TimeSpan.FromMinutes(30)) { Weather(); lastWeather = DateTime.Now; } }
public LsMqtt GetLastState(string name) { LsMqtt mqtt = null; foreach (LsProductItem pi in Products) { if (pi.Name == name) { byte[] buf = _client.DownloadData(_webapi + "product-items/" + pi.SerialNo + "/status"); using (MemoryStream ms = new MemoryStream(buf)) { DataContractJsonSerializer dcjs = new DataContractJsonSerializer(typeof(LsMqtt)); mqtt = (LsMqtt)dcjs.ReadObject(ms); ms.Close(); } } } return(mqtt); }
private void MqttMsgPublishReceived(object sender, MqttMsgPublishEventArgs e) { string Json = Encoding.UTF8.GetString(e.Message); Trace.TraceInformation("Mqtt received => {0}", Json); try { MemoryStream ms = new MemoryStream(e.Message); DataContractJsonSerializer dcjs = new DataContractJsonSerializer(typeof(LsMqtt)); LsMqtt jm = (LsMqtt)dcjs.ReadObject(ms); EventHandler <MyEventArgs> recv = Recv; _msgPoll = false; ms.Close(); recv(this, new MyEventArgs(jm)); } catch (Exception ex) { string s; Trace.TraceError("Mqtt received eception => {0}", ex.ToString()); s = Encoding.UTF8.GetString(e.Message); Trace.TraceError("Mqtt received message => {0}", s); } }
public override void OnReceive(Context context, Intent intent) { System.Diagnostics.Debug.WriteLine("Alarm {0} {1}", DateTime.Now, "ups"); //Every time the `RepeatingAlarm` is fired, set the next alarm //Intent intent = new Intent(context, typeof(RepeatingAlarm)); PendingIntent source = PendingIntent.GetBroadcast(context, 0, intent, 0); AlarmManager am = (AlarmManager)context.GetSystemService(Context.AlarmService); LsMqtt mqtt = App.Web.GetLastState("Gustav"); if (mqtt != null) { mqtt.Dat.Firmware = "1.23"; App.History.Add(new HistoryItem(DateTime.Now, mqtt)); //Context context = Android.App.Application.Context; //AlarmManager am = (AlarmManager)context.GetSystemService(Context.AlarmService); NotificationManager nm = (NotificationManager)context.GetSystemService(Context.NotificationService); if (App.NotifyMsg(mqtt.Dat)) { var notIntent = new Intent(context, typeof(MainActivity)); var contentIntent = PendingIntent.GetActivity(context, 0, notIntent, PendingIntentFlags.CancelCurrent); var builder = new NotificationCompat.Builder(context, MainActivity.cn) .SetAutoCancel(true) // Dismiss the notification from the notification area when the user clicks on it .SetContentIntent(contentIntent) // Start up this activity when the user clicks the intent. .SetContentTitle("Notify") // Set the title //.SetNumber(count) // Display the count in the Content Info .SetSmallIcon(Resource.Drawable.Icon_Notify) // This is the icon to display .SetContentText(mqtt.Dat.State.ToString()); // the message to display. nm.Notify(1000, builder.Build()); } } am.SetAndAllowWhileIdle(AlarmType.ElapsedRealtimeWakeup, SystemClock.ElapsedRealtime() + 5 * 60 * 1000, source); //Toast.MakeText(context, "repeating_received and after 15s another alarm will be fired", ToastLength.Short).Show(); }
public MyEventArgs(LsMqtt mqtt) { Mqtt = mqtt; }