public virtual async Task<WeatherInfo> GetWeatherInfoAsync() { System.Runtime.Serialization.Json.DataContractJsonSerializer jsonsr = new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(WeatherInfoBase)); // Command /get_dev_list /get_dev_list /get_dev_list //Parameters - - - //Response Body { list: [ { addr: “”, type: “”, pan: “”, mac: “”, visibility: 1, },...] } //array(object) //string string string string int //device id //device id device type device pan id MAC Address visibility WeatherInfoBase info = null; MyWebClient wc = new MyWebClient(); using (Stream stream = await wc.OpenReadTaskAsync(WeatherUriBase + "/env_sensor.get_dev_info")) { info = jsonsr.ReadObject(stream) as WeatherInfoBase; ; } info.info.Humidity *= 0.001; info.info.Temperature *= 0.1; info.info.PM25 *= 0.1; info.info.WindDirection *= 0.1; info.info.WindSpeed *= 0.1; info.info.WaterLevel *= 0.1; info.info.RainFall *= 0.1; return info.info; }
public CorrdinatorInfo GetDeviceInfo() { MyWebClient wc = new MyWebClient(); System.Runtime.Serialization.Json.DataContractJsonSerializer jsonsr = new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(CorrdinatorInfo)); Stream stream; CorrdinatorInfo retInfo = jsonsr.ReadObject(stream = wc.OpenRead(UriBase + "/info")) as CorrdinatorInfo; stream.Close(); stream.Dispose(); return retInfo; }
public virtual WeatherInfo GetWeatherInfo() { MyWebClient wc = new MyWebClient(); System.Runtime.Serialization.Json.DataContractJsonSerializer jsonsr = new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(WeatherInfoBase)); Stream stream; WeatherInfoBase retInfo = jsonsr.ReadObject(stream = wc.OpenRead(WeatherUriBase + "/env_sensor.get_dev_info")) as WeatherInfoBase; stream.Close(); stream.Dispose(); retInfo.info.Humidity *= 0.001; retInfo.info.Temperature *= 0.1; retInfo.info.PM25 *= 0.1; retInfo.info.WindDirection *= 0.1; retInfo.info.WindSpeed *= 0.1; retInfo.info.WaterLevel *= 0.1; retInfo.info.RainFall *= 0.1; return retInfo.info; }
public StreetLightInfo[] GetStreetLightList(string devid) { // Command /street_light.get_dev_list /street_light.get_dev_list /street_light.get_dev_list //Parameters dev (optional) string device id //Response Body { list: [ { dev: “”, lt: “2013-03-01-15:00:00”, to: true, rr: 0, rt: 0, rtc: “13-03-01-15-33-32”, l: [0,...], r: [0,...], t: [0,...], sch: { enable: 0, time: [0,...], level: [0,...] }, pm: [ { v: 0, a: 0, w: 0, pf: 0, f: 0, ap: 0, kwh_p: 0, kwh_n: 0 },...], cmt: “000000....” },...] } //array(object) //string string boolean int int string array(int) array(int) array(int) object int int int //array(object) //int int int int int int int int //hex[64] //device status //device id last report time time out RSSI Rx (%) RSSI Tx (%) rtc time dim level light sensor temp. sensor dimming schedule boolean time code dim level //power meter // voltage current walt power factor frequency apparent power kwh positive kwh negative //comment MyWebClient wc = new MyWebClient(); System.Runtime.Serialization.Json.DataContractJsonSerializer jsonsr = new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(StreetLightInfoList)); StreetLightInfoList infolist = null; if (devid == "*") using (Stream stream = wc.OpenRead(UriBase + "/street_light.get_dev_list")) { Console.WriteLine(UriBase + "/street_light.get_dev_list"); infolist = jsonsr.ReadObject(stream) as StreetLightInfoList; ; } else { using (Stream stream = wc.OpenRead(UriBase + "/street_light.get_dev_list?dev="+devid)) { infolist = jsonsr.ReadObject(stream) as StreetLightInfoList; ; } } int len = infolist.list.Length; return infolist.list.Take(len - 1).ToArray(); }
public async Task<DeviceInfo[]> GetDeviceListAsync() { System.Runtime.Serialization.Json.DataContractJsonSerializer jsonsr = new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(DeviceInfoList)); // Command /get_dev_list /get_dev_list /get_dev_list //Parameters - - - //Response Body { list: [ { addr: “”, type: “”, pan: “”, mac: “”, visibility: 1, },...] } //array(object) //string string string string int //device id //device id device type device pan id MAC Address visibility DeviceInfoList infolist = null; MyWebClient wc = new MyWebClient(); using (Stream stream = await wc.OpenReadTaskAsync(UriBase + "/get_dev_list")) { infolist = jsonsr.ReadObject(stream) as DeviceInfoList; ; } return infolist.list.Where(n => n != null).ToArray(); }
public void AddDeviceByMAC(string MAC) { // Command /add_device /add_device /add_device //Parameters mac string MAC address //Response Body - - - //Add device 0x4d38100301020304: Add device 0x4d38100301020304: Add device 0x4d38100301020304: //10.10.1.1:8080/add_dev_by_mac?mac=4d38100301020304 MyWebClient client = new MyWebClient(); using (Stream stream = client.OpenRead(UriBase + "/add_dev_by_mac?mac=" + MAC)) { while (stream.ReadByte() != -1) ; } }
public void Kick(string dev_id) { // Command /kick /kick /kick //Parameters name string device id //Response Body - - - //Remove device 8011 Remove device 8011 Remove device 8011 //10.10.1.1:8080/kick?name=8011 MyWebClient wc = new MyWebClient(); using (Stream stream = wc.OpenRead(UriBase + "/kick?name=" + dev_id)) { while (stream.ReadByte() != -1) ; } }
public void PermitJoinNode(int secs) { MyWebClient wc = new MyWebClient(); using (Stream stream = wc.OpenRead(UriBase + "/permit_join_node?seconds=" + secs.ToString())) { while (stream.ReadByte() != -1) ; } //System.Runtime.Serialization.Json.DataContractJsonSerializer jsonsr = new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(Coordinator2.CoordinatorResult)); //Stream stream; //Coordinator2.CoordinatorResult res = jsonsr.ReadObject(stream = wc.OpenRead(UriBase + "/info")) as CorrdinatorInfoBase; }
public void SetStreetLightRemark(string devid, string remark) { MyWebClient wc = new MyWebClient(); string result = ""; if (remark.Length > 64) result = remark.Substring(0, 64); else result = remark.PadRight(64, '0'); using (Stream stream = wc.OpenRead(UriBase + "/street_light.set_remark?dev=" + devid + "&remark=" + result)) { while (stream.ReadByte() != -1) ; } }
public void SetDeviceScheduleEnable(string devid, bool enable) { //10.10.1.1:8080/street_light.set_dev_schedule?dev=081f&enable=0 MyWebClient wc = new MyWebClient(); Stream stream; if (devid == "*") { stream = wc.OpenRead(UriBase + "/street_light.set_dev_schedule?enable=" + (enable ? "1" : "0")); } else { stream = wc.OpenRead(UriBase + "/street_light.set_dev_schedule?dev=" + devid + "&enable=" + (enable ? "1" : "0")); } while (stream.ReadByte() != -1) ; stream.Close(); stream.Dispose(); }
public async void SetDeviceScheduleAsync(string devid, string timeStr, string levelStr) { MyWebClient wc = new MyWebClient(); Stream stream; if (devid == "*") { stream = await wc.OpenReadTaskAsync(new Uri(UriBase + "/street_light.set_dev_schedule?time=" + timeStr + "&level=" + levelStr)); } else { stream = await wc.OpenReadTaskAsync(UriBase + "/street_light.set_dev_schedule?dev=" + devid + "&time=" + timeStr + "&level=" + levelStr); } while (stream.ReadByte() != -1) ; stream.Close(); stream.Dispose(); }
private StreetLightInfo[] GetDeviceSchedule(string devid) //version 2 { MyWebClient wc = new MyWebClient(); System.Runtime.Serialization.Json.DataContractJsonSerializer jsonsr = new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(StreetLightInfoListBase)); StreetLightInfoListBase infolist = null; if (devid == "*") using (Stream stream = wc.OpenRead(UriBase + "/street_light.get_dev_info")) { Console.WriteLine(UriBase + "/street_light.get_dev_info"); infolist = jsonsr.ReadObject(stream) as StreetLightInfoListBase; ; } else { using (Stream stream = wc.OpenRead(UriBase + "/street_light.get_dev_info?dev=" + devid)) { infolist = jsonsr.ReadObject(stream) as StreetLightInfoListBase; ; } } int len = infolist.list.Length; return infolist.list.Take(len - 1).ToArray(); }
public virtual DeviceInfo[] GetDeviceList() //version 2 { MyWebClient wc = new MyWebClient(); System.Runtime.Serialization.Json.DataContractJsonSerializer jsonsr = new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(DeviceInfoListBase)); // Command /get_dev_list /get_dev_list /get_dev_list //Parameters - - - //Response Body { list: [ { addr: “”, type: “”, pan: “”, mac: “”, visibility: 1, },...] } //array(object) //string string string string int //device id //device id device type device pan id MAC Address visibility DeviceInfoListBase infolist = null; using (Stream stream = wc.OpenRead(UriBase + "/street_light.get_dev_info")) { infolist = jsonsr.ReadObject(stream) as DeviceInfoListBase; ; } return infolist.list.Where(n => n != null).ToArray(); }
public void SetDeviceDimLevel(string devid, int level) { MyWebClient client = new MyWebClient(); string args; //if(devid=="*") // args = "/street_light.set_dim_level?level=" + level; //else args = "/street_light.set_dim_level?dev=" + devid + "&level=" + level; using (Stream stream = client.OpenRead(new Uri(UriBase + args, UriKind.Absolute))) { while (stream.ReadByte() != -1) ; // System.Diagnostics.Debug.Print(UriBase + "/street_light.set_dim_level?dev=" + devid + "&level=" + level); } }
public void PermitJoinNode(int secs) { MyWebClient wc = new MyWebClient(); using (Stream stream = wc.OpenRead(UriBase + "/permit_join_node?seconds=" + secs.ToString())) { while (stream.ReadByte() != -1) ; } }
public async void SetDeviceDimLevelAsync(string devid, int level) { // /street_light.set_dim_level /street_light.set_dim_level /street_light.set_dim_level //Parameters dev (optional) string device id Parameters //level int dim level //Response Body - - - //Remark dim level = 0 (off), 20~100 (level in %) dim level = 0 (off), 20~100 (level in %) dim level = 0 (off), 20~100 (level in %) //Example Set dimming level of device 8020 to 85% Set dimming level of device 8020 to 85% Set dimming level of device 8020 to 85%Example //10.10.1.1:8080/street_light.set_dim_level?dev=8020&level=85 //if(devid=="*") // using (Stream stream = wc.OpenRead(UriBase + "/street_light.set_dim_level?level=" + level)) // { // while (stream.ReadByte() != -1) ; // } //else string args; //lock (this) //{ MyWebClient client = new MyWebClient(); //if (devid == "*") // args = "/street_light.set_dim_level?level=" + level; //else args = "/street_light.set_dim_level?dev=" + devid + "&level=" + level; using (Stream stream = await client.OpenReadTaskAsync(new Uri(UriBase + args, UriKind.Absolute))) { while (stream.ReadByte() != -1) ; // System.Diagnostics.Debug.Print(UriBase + "/street_light.set_dim_level?dev=" + devid + "&level=" + level); } // client.Dispose(); //} // client.Dispose(); }
public void ChangeRFChanel(int chanelno) { // /change_rf_channel /change_rf_channel /change_rf_channel //Parameters channel int channel index //Response Body - - - //Example Change RF channel to 13: Change RF channel to 13: Change RF channel to 13:Example //10.10.1.1:8080/change_rf_channel?channel=13 // MyWebClient wc = new MyWebClient(); using (Stream stream = wc.OpenRead(UriBase + "/change_rf_channel?channel=" + chanelno.ToString())) { while (stream.ReadByte() != -1) ; } }
public void SetDeviceRTC(string devid, DateTime dt) { //10.10.1.1:8080/street_light.set_rtc? dev=8201&rtc=13-08-31-12-10-11 MyWebClient wc = new MyWebClient(); Stream stream; if (devid == "*") stream = wc.OpenRead(UriBase + "/street_light.set_rtc?rtc=" + dt.ToString("yy-MM-dd-HH-mm-ss")); else stream = wc.OpenRead(UriBase + "/street_light.set_rtc?dev=" + devid + "&rtc=" + dt.ToString("yy-MM-dd-HH-mm-ss")); while (stream.ReadByte() != -1) ; stream.Close(); stream.Dispose(); }
public virtual async void SetDeviceScheduleAsync(string devid, string timeStr, string levelStr) { MyWebClient wc = new MyWebClient(); Stream stream; System.DateTime dt = DateTime.Now; if (devid == "*") { stream = await wc.OpenReadTaskAsync(new Uri(UriBase + "/street_light.set_dev_schedule?time=" + timeStr + "&level=" + levelStr/*+"&on="+dt.Year+"-"+dt.Month+"-"+dt.Day*/)); } else { stream = await wc.OpenReadTaskAsync(UriBase + "/street_light.set_dev_schedule?dev=" + devid + "&time=" + timeStr + "&level=" + levelStr/* + "&on=" + dt.Year + "-" + dt.Month + "-" + dt.Day*/); } while (stream.ReadByte() != -1) ; stream.Close(); stream.Dispose(); }