public async void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; context.Response.Write("DONE"); string ip = context.Request["ip"]; string nazwa = context.Request["name"]; DB2DataContext db = new DB2DataContext(); HttpClient client = new HttpClient(); client.BaseAddress = new Uri($"http://{ip}"); HttpResponseMessage response = await client.GetAsync("/status"); RootObject rt = new RootObject(); rt = await response.Content.ReadAsAsync <RootObject>(); string str = await response.Content.ReadAsStringAsync(); shelly s = new shelly(); s.datetime_ev = DateTime.Now; s.nazwa = nazwa; s.hum = (int)rt.hum.value; s.tC = (int)rt.tmp.tC; s.tF = (int)rt.tmp.tF; s.bat_lvl = (int)rt.bat.value; db.shellies.InsertOnSubmit(s); db.SubmitChanges(); }
public async void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; context.Response.Write("Hello World"); string ip = context.Request["ip"]; string nazwa = context.Request["name"]; HttpClient client = new HttpClient(); client.BaseAddress = new Uri($"http://{ip}"); string get_string = await client.GetStringAsync("/json"); get_string = get_string.Replace("Free RAM", "FreeRAM").Replace("nan", "0").Replace(".00", "");; RootObject ro = JsonConvert.DeserializeObject <RootObject>(get_string); ip = ""; DB2DataContext db = new DB2DataContext(); shelly s = new shelly(); s.datetime_ev = DateTime.Now; s.nazwa = nazwa; s.hum = (int)ro.Sensors[0].Humidity; s.tC = (int)ro.Sensors[0].Temperature; s.tF = 0; s.bat_lvl = 0; db.shellies.InsertOnSubmit(s); db.SubmitChanges(); }
public async void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; try { string ip = context.Request["ip"]; HttpClient client = new HttpClient(); client.BaseAddress = new Uri($"http://{ip}"); HttpResponseMessage response = await client.GetAsync("/status.xml"); string str = await response.Content.ReadAsStringAsync(); var reader = new StringReader(str.Replace("iso-8859-1", "utf-8")); XmlSerializer serializer = new XmlSerializer(typeof(Response)); Response resp = (Response)serializer.Deserialize(reader); DB2DataContext db = new DB2DataContext(); shelly temp = new shelly(); temp.bat_lvl = 100; temp.tC = (int)resp.Temp1; temp.tF = 0; if (ip == "192.168.1.2") { temp.nazwa = "Wysyłane - kotłownia"; } else { temp.nazwa = "?"; } temp.datetime_ev = DateTime.Now; temp.hum = -1; db.shellies.InsertOnSubmit(temp); db.SubmitChanges(); } catch { } context.Response.Write("OK"); }