Søk i nettsamfunnet
Viser resultater for emneknaggene 'csharp'.
Fant 1 resultat
-
Hei, har nettopp startet med homeseer og ønsker å lage noen enkle skript i c#. Men det er vist ikke like enkelt... Scenario: Har skrevet data til en influxdb og vil lese disse igjen (med en mean aggregering). Problemet er at jeg vil bruke Newtonsoft.Json.Net til å parse JSON resultatet. See hele koden under. Problemet er hvordan refererer jeg til Newtonsoft.Json.dll? I følge dokumentasjonen jeg fant her (under c# scripting) så står det: Så det gjorde jeg... Jeg ser at Newtonsoft.Json.dll ligger i bin\Homeseer folderen og tenkte der for at det ikke var nødvending å legge til noe path. Har prøvd mye men får feil hele tiden. Det virker ikke som //css_reference har noen effekt. Kode: //css_reference Newtonsoft.Json.dll; using Newtonsoft.Json; using Newtonsoft.Json.Linq; public object Main(object param) { var sensitivity = double.Parse((string)param); var deviceId = 271; var INFLUX_DB_SERVER_IP = "10.0.0.104"; var INFLUX_DB_SERVER_PORT = "8086"; var INFLUX_DB_DATABASE_NAME = "homeseer"; var query = "q=select mean(value) from Downstairs_Bathroom_Humidity where time > now() - 1d"; var url = "http://" + INFLUX_DB_SERVER_IP + ":" + INFLUX_DB_SERVER_PORT + @"/query?db=" + INFLUX_DB_DATABASE_NAME; var request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url); request.ContentType = "application/x-www-form-urlencoded"; request.Method = "POST"; try { request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; var data = System.Text.Encoding.ASCII.GetBytes(query); request.ContentLength = data.Length; request.Timeout = 5000; var stream = request.GetRequestStream(); try { stream.Write(data, 0, data.Length); } finally { stream.Close(); } var response = (System.Net.HttpWebResponse)request.GetResponse(); var responseString = new System.IO.StreamReader(response.GetResponseStream()).ReadToEnd(); var result = Newtonsoft.Json.JsonConvert.DeserializeObject(responseString); var meanValue = (double) ((Newtonsoft.Json.Linq.JValue)((Newtonsoft.Json.Linq.JContainer)result)["results"].First["series"].First["values"].First.Last).Value; var value = hs.DeviceValue(deviceId); if((value - sensitivity) > meanValue) { hs.TriggerEvent("Run Ventilator for 10 minuttes"); hs.WriteLog("Julius-Ventilation", "Info: Triggered Ventilation"); } } catch (System.Exception ex) { hs.WriteLog("Julius-Ventilation", "Error: " + ex.Message); } return 0; } Feil medling: Compiling script C:\Program Files (x86)\HomeSeer HS3\scripts\CSharpTest.cs: {interactive}(93,30): error CS0103: The name `Newtonsoft' does not exist in the current context {interactive}(93,41): error CS0023: The `.' operator cannot be applied to operand of type `' {interactive}(93,17): error CS0825: The contextual keyword `var' may only appear within a local variable declaration {interactive}(95,106): error CS0841: A local variable `result' cannot be used before it is declared {interactive}(95,74): error CS0246: The type or namespace name `Newtonsoft' could not be found. Are you missing a using directive or an assembly reference? {interactive}(95,17): error CS0825: The contextual keyword `var' may only appear within a local variable declaration {interactive}(101,44): error CS0841: A local variable `meanValue' cannot be used before it is declared {interactive}(11,17): warning CS0414: The private field `Script.hs' is assigned but its value is never used