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 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 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 async void SetDeviceScheduleEnableAsync(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 =await wc.OpenReadTaskAsync(UriBase + "/street_light.set_dev_schedule?enable=" + (enable ? "1" : "0")); } else { stream =await wc.OpenReadTaskAsync(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(); }
public async Task SetDeviceRTCAsync(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 =await wc.OpenReadTaskAsync(UriBase + "/street_light.set_rtc?rtc=" + dt.ToString("yy-MM-dd-HH-mm-ss")); else stream =await wc.OpenReadTaskAsync(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(); }