Conclusion:
the \ \ in the ‘strange’ JSON-string seems linked to the u in the pprinted ‘data’ for Status or QC.
Indicator in the Tempest data to distinguish ‘Status&QC’-info from ‘real’ data?
Using python3.x these u’s are absent, and all output from Peter’s script per message has same type of layout.
Further down in Peter’s script these data are input for the dictionaries.
Have the nagging feeling that the json-module imposes requirements to earlier stage:
if ‘data’ is not a ‘clean&legal’ content for generation of dictionary ‘observations’, then the dictionary is not properly filled
=> not compatible with the added, ‘standard’ json generation-function
=> the script strikes due to deviation.
With module dicttoxml a similar experience:
also not digesting the dictionary ‘observations’ (probably for same reason).
Differnt error reports for python2.x and python3.x
Comes the question:
how to simply ‘clean/shrink’ the data (and hence the resulting dictionary) to produce dictionaries compatible with json.dump?
Some aspect of the reference dictionary-mapping?
For the second error it looks like you are trying to dump the original data object, not the data json. It should be: json.dump(data_json, outfile)
As for the original issue, the reason you can’t dump the observations dict is because the keys are tuples, as it indicates in the error TypeError: key ('Illuminance', 'Lux') is not a string. Depending on what you are wanting to do with the json there are a few ways you could fix this. The easiest would probably be to edit the OBS_ST_MAP variable to just be strings and get rid of the units:
string_map = [key[0] for key in OBS_ST_MAP]
observations = dict(zip(string_map , data_json[‘obs’][0]))
Then you can dump that out to a file.
If you wanted to keep the units you could concatenate them together with
string_map = [key + " - " + units for key, units in OBS_ST_MAP]
Thanks for the hints.
You confirm that I was near, but not yet in touch with the ‘culprits’ causing the error reports.
Aim for the contents of an output json-file and xml-file is a set of labels in combination with values.
Similar to json-file/xml-files coming from e.g. solar-inverters or from ESP8266s with ESPEasy.
Planned application setup:
one nodal point for generation and then distribution of the json/xml-files as input for various applications, both meteo and domotics.
Have tweaked the original script and put the result at Tempest Weather System - Domoticz for further use for anyone interested.
The tweaking description should explain the changes made and why.
Lightning-functionality hard to test, because thunder&flashes only occur unplanned.
Presently I hear&see it happening rather fiercefully, info reported through Weatherflow & WU, no errors in script-running, but also no registration & reporting by the ‘Simple’ UDPListener of the Lightning-events. Somebody a hint what correction required to the scriptsegment below?**
# Original scriptlines:
# observations = dict(zip(EVT_STRIKE_MAP, data_json['evt']))
# observations['Datetime'] = datetime.datetime.fromtimestamp(observations[('Time Epoch', 'Seconds')])
# For edit of the EVT_STRIKE_MAP variable to just be strings and get rid of the units:
string_map = [key[0] for key in EVT_STRIKE_MAP]
observations = dict(zip(string_map , data_json['evt'][0]))
# Insert dictionary into JSON-file
with open('/home/pi/Tempest_SInfo.json', 'w') as outfile:
json.dump(observations, outfile)
print ('StrikeInfo')
pprint.pprint(observations)
At the end of the following scriptline tried several variations for [‘evt’][0], but without any effect
I’ve been logging the raw UDP data for months now and have never seen an ‘evt’ event, despite have lightning strike what seemed to be fairly close. I am not sure where the data is being pulled from for the app.
Anton, your Tempest will be updated in a few minutes (will be down for a good 10 minutes while doing so, don’t reboot, just let it finish)
Once done I’ll ping you again and from there test your script again.
This should already make sure the data is available, before you go bonkers
The JSON-file from Weatherflow-server includes Lightning-info having resemblance to actual events.
Therefore ‘in some way’ the sensor-hub must generate a message for that purpose as listed in WeatherFlow Tempest UDP Reference - v143
Have tried to read with Tempest API , but difficulty with ID-insertion.
Any known ID for my Tempest is resulting in either 401-error or 404-error.
[ More, deeper trouble needed for me going bonkers …]
Anton, it was not the hub’s firmware that needed update but the Tempest. It has now been done and your script should now be able to retrieve the lightning data from UDP. And as I’m not a coder I let others help you out with that part
Your Tempest firmware is not good. Not sure I’ll find someone on watch today. Best option is to open a support ticket and ask to update your Tempest do enable the lightning detection via UDP. This way your request isn’t lost in the flow of daily things. They’ll come back to you tomorrow.