INTEGRATION
...
Indata-sensorer
Sensor-Online's API

Skicka in data via API:et

4min
du kan använda sensor online för visualiserng rapporter, larmning e t c med data som kommer från andra 3\ e parts applikationer, du använder api\ et för att skriva in ny data exempel kod c# ( vi hjälper gärna till med stöd och support ) { sensoronlineapi so = new sensoronlineapi(); so addtagdata(hardwareserial, type, value); } using system; using system collections generic; using system diagnostics; using system globalization; using system io; using system linq; using system reflection; using system runtime compilerservices; using system security; using system text; using system threading tasks; using microsoft visualbasic; using system net http; using newtonsoft json; using newtonsoft json linq; public class sensoronlineapi { private httpclient webclient = new httpclient(); public string token; const string baseuri = "http //api sensor online se"; private async task authorizeasync(object email, object password) { var user = new usermodel(); user email = email; user password = password; var response = await webclient postasync(baseuri + "/api/users/authenticate", new stringcontent(jsonconvert serializeobject(user), encoding utf8, "application/json")); string json = response content readasstringasync() result; token = jobject parse(json)("token"); } public async task addtagdata(object deveui, object key, object value) { if (token == null) // replace with your account id and password await authorizeasync("xxxxyyyzzzn\@iot ab se", "zzzzxxxxyyyy"); var tagdata = new tagdata(); tagdata key = key; tagdata value = value; webclient defaultrequestheaders authorization = new system net http headers authenticationheadervalue("bearer", token); var res = await webclient postasync(baseuri + "/api/tag/" + deveui + "/tagdata", new stringcontent(jsonconvert serializeobject(tagdata), encoding utf8, "application/json")); } } exempel kod vb net ( vi hjälper gärna till med stöd och support ) anrop till klassen som skickar in data, skicka med id, typ och värde dim so as sensoronlineapi = new sensoronlineapi so addtagdata(hardwareserial, type, value) klassen för att addera data i sensor onlines databas så du kan använda data från 3\ e parts system imports system imports system collections generic imports system diagnostics imports system globalization imports system io imports system linq imports system reflection imports system runtime compilerservices imports system security imports system text imports system threading tasks imports microsoft visualbasic imports system net http imports newtonsoft json imports newtonsoft json linq public class sensoronlineapi private webclient as httpclient = new httpclient() public token as string const baseuri as string = "http //api sensor online se" private async function authorizeasync(byval email as object, byval password as object) as task dim user = new usermodel() user email = email user password = password dim response = await webclient postasync(baseuri & "/api/users/authenticate", new stringcontent(jsonconvert serializeobject(user), encoding utf8, "application/json")) dim json as string = response content readasstringasync() result token = jobject parse(json)("token") end function public async function addtagdata(byval deveui as object, byval key as object, byval value as object) as task if token is nothing then await authorizeasync("xxxxyyyzzzn\@iot ab se", "zzzzxxxxyyyy") dim tagdata = new tagdata() tagdata key = key tagdata value = value webclient defaultrequestheaders authorization = new system net http headers authenticationheadervalue("bearer", token) dim res = await webclient postasync(baseuri & "/api/tag/" & deveui & "/tagdata", new stringcontent(jsonconvert serializeobject(tagdata), encoding utf8, "application/json")) end function end class exempelkod python (micropython) inloggning och uppladdning av data till en existerande tagg/nyckel from lib import urequests class sensoronline token = false baseurl = "https //api sensor online se/api" def authorize(self, email, password) payload = {"email" email, "password" password} authurl = self baseurl + '/users/authenticate' try res = urequests post( authurl, headers={"content type" "application/json", "accept" "application/json"}, data=str(payload)) self token = res json() get("token", false) except print("auth failed!") def uploaddata(self, tag, key, data) if tag != none try payload = {"key" key, "value" data} url = self baseurl + "/tag/" + tag + "/tagdata" bearer = "bearer " + self token urequests post( url, headers={"content type" "application/json", "accept" "application/json", "authorization" bearer}, data=str(payload)) except print("error updating data to sensoronline ")