Community
OpenEnergyMonitor

OpenEnergyMonitor Community

EmonTX not connecting properly to emoncms over https using nginx

Tags: #<Tag:0x00007fc9bcdbf960> #<Tag:0x00007fc9bcdbf708>

Hi,
I’ve got an emontx unit with the wifi module which I’m trying to get talking to the docker install of emoncms that is running on a rpi under ubuntu.
I’ve got the hardware all connected up and reading the energy usage from the house wiring, and this is also publishing to MQTT on the same destination rpi for (eventually) talking to home assistant.
so whilst the MQTT section in the web interface shows “connected: yes”, the section for emoncms doesn’t want to connect.
The rpi is set up with two virtualhosts in nginx (for home assistant and emoncms that are both running under docker), and I will admit I had a bit of trouble getting emoncms to run behind https, eventually needing to add an extra header to the reverse-proxy config to convince it that it was all ok to do so.

So.
The settings for emoncms in the esp module are these:
emoncms server: emoncms (this is resolvable in dns)
emoncms path: {empty}
emoncms node name: mainpower
write apikey: {api write key from emonsmc user profile}
SSL SHA-1 Fingerprint: {fingerprint extracted from server using openssl command}

I can see there’s some sort of ssl transaction between the devices with tcpdump, but obviously not what that is.
I did see a few GET requests in the nginx logs with the appropriate data earlier, but nothing more recently.

Can anyone point me in the right direction for figuring this out?..
I have a suspicion the emontx isn’t liking where it is trying to send to, but not sure what exactly.

Thanks,
Sean

So I’ve solved my own problem with an nginx ‘if’ statement for the non-https server block…
Basically, if the user agent string is the one from the emontx, proxy to the docker instance of emoncms.
If it isn’t that device, redirect to https as normal.
This thing seems to have trouble with nested curly brackets, so you essentially put the following in the server block for port 80:
if ($http_user_agent != “ESP8266HTTPClient” ) {
return 301 https://$host$request_uri;
}

1 Like