How to code for a function that would wait for an Http address to respond before sending a cmd?

Hi everybody,

I'm looking for a way to have a function to wait for an http address (a device that has its ID on my hub) to respond within a relatively extended time frame, before sending a new request. Is it possible without triggering the built-in warn message informing that the host is unreachable?

Thank you in advance!

If you are talking about sending a GET request from HE to another server, then you can build the message yourself using the raw message.
http://docs.hubitat.com/index.php?title=HubAction_Object

@chuck.schwer would be the one who might be able to answer the question in greater detail.

I know how to send a http get or even post. I need a way to test the connection beforehand and declare a value based on success or failure.

I thought the whole point of an HTTP request was that everything comes back in the response. The response with include the status in the headers. What type of system are you trying to send a request to?

I believe you can do this by simply wrapping the http request in a try/catch. It should allow you to do you own error handling.

1 Like

At this stage it's just a thought but mainly I have built a can opener that opens and pours can food while I'm away. It has a redundant power switch so it can be hard reset remotely and, above all, knowing it involves some heavy duty 12-24v servos, it prevents any possible cascade failure that could be a serious fire hazard due to overheating servos. This sutdown system is a complete shutdown managed by an ESP8266 that turns off the main power to the main controller, Atmega2560 (had to go for this due the amount of available I/O ports) using a regular ethernet shield (another redundancy with the ESP also connected to my network). Now, the issue I'm having is that the Ethernet Shield takes forever, up to one minute, to boot properly when not on USB (probably a bad clone, I know... but no time to get a new one for now, leaving soon to my dear country, France... :slight_smile: - don't be jalous!)

So here is the thing: ESP boots the whole system. Then my device driver uses a set of 2 ips, one to control the ESP based power switch control and another one to control the cat feeder, this one being connected with the Ethernet Shield on Atmega. So, when I turn on Can Opener via ESP, I'd like it to wait for proper response from the Ethernet Shield so it can then send the command to feed the cats.

I'll look into try/catch method, which I already use although I need to figure out how to have it recursively monitor the response, or rather the lack thereof. In all honesty I asked the question in case someone among our community had already something readily available so I could fix this quickly before I leave and finish taking care of the optimization of the can opener itself (especially the part where it pours the food into a plate, which is the one involving the biggest amount of moving parts! Had a robotic arm doing the job in the past, but worked only at 60% due to the lack of precision of the servos I was using and limited budget to get better sensors)

That thing sounds interesting . Do you have a picture of it you could post?

:flushed:
You lost me at "can opener" lol. It sounds pretty awesome but I can't follow the esp-ception. I would love to see a write-up and video of this puppy in action though. Maybe when you get back from Mother France?

1 Like

@stephack :

"Can opener August 2019 - Google Drive

2 Likes

LMAO....I don't know how well that will work to feed your cats. He looked pretty scared of the thing. Plus, what do you do with the empty can? But it is very cool. So, you are trying to initiate the process of opening the can? Or are you waiting for a message back that it was successful? If the later, I would recommend that your can opener store the success for a future get request. That way, Hubitat to re-poll the opener to check if the whole process completed successfully or not.

Thanks for your answer @Ryan780 . The cat is actually used to this, except this is a new version and, yes, he eats from it. Used to have a clamp catching the can, pouring the food into a clean plate, then the plate pushed out. But it took too much room and too many moving parts (the clamp would even wash itself into a cleaning solution afterward...) and, budget wise, I had to lower the cost of the whole thing. Like this it is a bit dirty, but at least it works reliably.

For what regards what I looking forward to do, it is to make sure the device is up and ready to receive http requests after being powered on by the auxiliary controller (ESP8266) and so I need to check if the web server is responding. I guess I just gotta work within the try/catch and repeat until successful, actually... Haven't had time to work on this today because, precisely, I'm trying to figure a cleaner final step, notably by designing and 3D printing some especially designed stackable and pushable plates!

Very cool!

Why don’t you send a unsolicited message from the Ethernet Shield back to hubitat, the same way as HubDuino works. As long as the DNI is correct, you can send a message to your Hub on port 39501. That would call the parse method and based on that message you could continue in your flow

2 Likes

Good idea -- I don't know why I haven't thought about this, especially knowing that I already use the port 39501 (actually all my ESP's and arduino based devices have the benefit of communicating with both ST port 39500 (this dates from a methodical preparation of a migration and prevented me from getting too much in trouble with my family at home... didn't work so well anyway, but that's another topic) and HE hubs (yes, dual Hub library) and also have an xml js interface for redundancy in case both hubs fail).

What you suggest is that Ethernet shield communicates with the hub to say "hey! I'm connected now!". It should work, indeed! I'll look into it as soon as I find some time. Really, I can't believe I didn't think of this...

Thanks for the suggestion!

1 Like