thorrak / tiltbridge

Tilt Hydrometer to WiFi Bridge
http://www.tiltbridge.com/
Other
61 stars 27 forks source link

Will not post to mDNS Address #14

Closed lbussy closed 3 years ago

lbussy commented 4 years ago

When posting to an mDNS name, the post fails:

Calling send to Fermentrack
Data to send: {"mdns_id":"tiltbridge","tilts":null}
Error on sending POST: -1

I'm fairly certain HTTPClient::begin() will not resolve mDNS, however, DNS queries will so you can get the IP and cache it before that.

lbussy commented 3 years ago

This can be addressed the same way I did it in Brew Bubbles. Use LCBUrl to get/cache the IP address (it's available in Arduino as well as PlatformIO library manager):

https://github.com/lbussy/brew-bubbles/blob/a4025661521438266cced7ee42fb1690e49c59cf/src/target.cpp#L80-L105

Then you can use WiFiClient::client() to send manually (rather than using HTTPClient::client():

https://github.com/lbussy/brew-bubbles/blob/a4025661521438266cced7ee42fb1690e49c59cf/src/pushhelper.cpp#L37-L168

Using LCBUrl will allow you to parse out sections of a longer, more complex URL. I don't think I am using the LCBUrl::getIP() method in Brew Bubbles yet (ironic), so look at that to make things even simpler.

(You'll also note some IP address validity checks that you can apply where you are doing some convoluted work presently.)