IUNGO Forum
Het Forum is voor IUNGO gebruikers en wordt ook vooral beantwoord door andere IUNGO gebruikers.
IUNGO maakt zelf beperkt gebruik van het Forum.
Specifieke vragen of storingen dus graag melden via de mail naar ons info adres.
Het Forum is voor IUNGO gebruikers en wordt ook vooral beantwoord door andere IUNGO gebruikers.
IUNGO maakt zelf beperkt gebruik van het Forum.
Specifieke vragen of storingen dus graag melden via de mail naar ons info adres.
Goedenavond,
Ik probeer via een browser (Safari en Chrome) de api te benaderen waarbij ik een json response verwacht:
https://xxxxxxxxxxxxx.iungoconnect.eu/iungo/api_request/?cmd=dailylog&oid=xxxxxxxx&prop=usage
Ik krijg echter de response ‘Error parsing JSON’:
{"ok":false,"type":"response","time":3.1251925975084e-05,"rv":false,"error":"Error parsing JSON","systime":1571771833}
Iemand enig idee hoe ik een json response kan krijgen?
Dank en groet, Ronald
De foutmelding geeft aan dat de aanvraag (Call) niet in correct JSON formaat is.
De API is het eenvoudigst te bereiken via Curl, zie forum discussie: Hoe krijg ik via de API toegang tot iungo
Misschien kan je aangeven wat je doel is om data via API te onttrekken zodat we meer gericht een antwoord kunnen geven.
Hallo Rodney,
Dank voor je antwoord. Hieronder de Python code die ik gebruik om mijn gas en electriteits gebruik uit te lezen. De code heeft twee jaar probleemloos gedraaid maar ik krijg het nu niet meer aan de praat.
Heb je wellicht suggesties?
Dank en groet,
Ronald
import requests import json import time import datetime import urllib3 import certifi cafile = certifi.where() oid = 'xxxxxxxx' url = 'https://xxxxxxxxxxxx.iungoconnect.eu/api_request' def iungo_API(prop): gas_price = 0.730 #Euro per m3 T1_price = 0.195 #Euro per kWh T2_price = 0.217 #Euro per kWh # payload1 requests the timestamp of the last stored value payload1 = '{"seq":1,"method":"datalog_get_last","arguments":{"oid":"' + oid +'", "prop": "' + prop + '"}}' s1 = requests.post(url, data=payload1, verify = cafile).json() # retrieve the useful data from the response, c1 is the timestamp of the last stored value a1 = s1['rv']['data'] b1 = str(a1[0]) c1 = b1[b1.find("[")+1:b1.find("]")] # payload0 requests the first timestamp and value of the day payload0 = '{"seq":1,"method":"datalog_get_first_of_day","arguments":{"timestamp": ' + c1 + ',"oid":"' + oid +'", "prop": "' + prop + '"}}' s0 = requests.post(url, data=payload0, verify = cafile).json() # retrieve the useful data from the response, c0 is the value at the start of the day a0 = s0['rv'] b0 = str(a0) c0 = b0[b0.find("'value':")+9:b0.find(",")] #payload2 requests the value for the last stored timestamp payload2 = '{"seq":1,"method":"datalog_get","arguments":{"t2": ' + c1 + ',"t1":' + c1 + ',"oid":"' + oid +'", "prop": "' + prop + '"}}' s2 = requests.post(url, data=payload2, verify = cafile).json() # retrieve the useful data from the response, c2 is the current value a2 = s2['rv']['data'] b2 = str(a2[0]) c2 = b2[b2.find(",")+1:b2.find("]")] # define the value of t_min [sec] depending on prop if prop == 'gas': t_min = 3600 if prop == 'T1' or prop == 'T2': t_min = 300 #payload3 requests the value t_min seconds before the last stored timestamp to calculate current usage c1_tmin = str(int(c1) - t_min) payload3 = '{"seq":1,"method":"datalog_get","arguments":{"t2": ' + c1_tmin + ',"t1":' + c1_tmin + ',"oid":"' + oid +'", "prop": "' + prop + '"}}' s3 = requests.post(url, data=payload3, verify = cafile).json() # retrieve the useful data from the response, c3 is the value of t_min seconds ago a3 = s3['rv']['data'] b3 = str(a3[0]) c3 = b3[b3.find(",")+1:b3.find("]")] # payload4 requests the the first value of the current year # retrieve the current date, element current_date_time[0] = current year current_date_time = time.gmtime(time.time()) # retrieve the unix epoch time for the beginning of the current year #time1 = str(datetime.datetime(current_date_time[0],1,1,0,0).timestamp()) time0 = datetime.datetime(current_date_time[0],1,1,0,0).strftime('%s') #print ('time1: ', time1, ' time0: ', time0) payload4 = '{"seq":1,"method":"datalog_get_first_of_day","arguments":{"timestamp": ' + time0 + ',"oid":"' + oid +'", "prop": "' + prop + '"}}' s4 = requests.post(url, data=payload4, verify = cafile).json() print('s4') print(s4) a4 = s4['rv'] b4 = str(a4) c4 = b4[b4.find("'value':")+9:b4.find(",")] daily_use = float(c2) - float(c0) yearly_use = float(c2) - float(c4) if prop == 'gas': current_use = ((float(c2) - float(c3))*(3600/t_min)) daily_cost = daily_use * gas_price yearly_cost = yearly_use * gas_price if prop == 'T1': current_use = 1000*((float(c2) - float(c3))*(3600/t_min)) daily_cost = daily_use * T1_price yearly_cost = yearly_use * T1_price if prop == 'T2': current_use = 1000*((float(c2) - float(c3))*(3600/t_min)) daily_cost = daily_use * T2_price yearly_cost = yearly_use * T2_price #print '----------------------------------------' #print 'prop :', prop #print 'start of day :', b0 #print 'curent timestamp :', c1 #print 'current value :', c2 #print 'past value :', c3 #print 'current gebruik :', 1000*((float(c2) - float(c3))*12), ' W' #print 'current gebruik :', (float(c2) - float(c3))*12, ' m3/hour' #print 'dagverbruik :', float(c2) - float(c0) #print '----------------------------------------' return round(current_use,2), round(daily_use,2), round(daily_cost,2), round(yearly_cost,2) gas_use = iungo_API('gas') print ('----------------------------------------') print ('current gas use : ', gas_use[0], 'm3/hour') print ('daily cum gas use : ', gas_use[1], 'm3') print ('daily cum gas cost : ', gas_use[2], ' Euro') print ('yearly cum gas cost : ', gas_use[3], 'Euro') print ('----------------------------------------') T1_use = iungo_API('T1') T2_use = iungo_API('T2') print ('current electricity use : ', T1_use[0] + T2_use[0], ' W') print ('daily cum electricity use : ', T1_use[1] + T2_use[1], ' kWh') print ('daily cum electricity cost : ', T1_use[2] + T2_use[2], 'Euro') print ('yearly cum electricity cost : ', T1_use[3] + T2_use[3], 'Euro') print ('----------------------------------------')
Ik zie zo niet waarom het na twee jaar fout zou gaan...
Het beste lijkt mij om de request in python te printen voordat je ze stuurt en deze rechtstreeks via interne netwerk op iungo te proberen (is zowiezo aan te raden bij gebruik van de API).
De Call lijkt iungo wel te bereiken maar iungo kan hem niet uitvoeren, dit zou dus ook kunnen komen doordat het oid veranderd is (bijvoorbeeld door slimme meter wissel !!).
Het oid afhankelijk van type slimme meter (DSMR2 of DSMR 4>)
Controleren van de call via de control pagina van iungo is meestal een goed begin...
Ik heb de oid gecontroleerd en die klopt. Ik heb de call via de control pagina geprobeerd en ook als curl via de command line. Wat ik ook probeer ik krijg een <Response [200] maar geen json format. Wel krijg ik een html code (zie onder). Als ik de response opsla als .html en vervolgens open in een browser krijg ik het toegangsscherm van iungo voor externe toegang. Dit scherm lijkt om het password te vragen. Is het nodig om met de API call een password mee te sturen?
Gebruik als url:
url = 'http:///iungo/api_request'
Dank Rodney, werkt nu weer!