Homey Community Forum

Homey HTTP Post\Get in Java

Hi,

I’m having a go at creating my first Homey app in Java, trying to access energy usage from a smart meter. I have found and modified a python script which is correctly able to pull the data in by using http Post and Get requests, so now trying to recreate that in the Homey app, unfortunately, although I’m very experienced with C++ I’m totally new to Java!

I have found some examples that seems explain the sort of thing I want to do using the HttpRequest and HttpUrlConnection classes, however, trying to include the required java.net.http.* in my project seems to fail, I don’t know if this is because I need to set something up differently, or maybe I can’t use those classes with Homey?

Hoping maybe someone could give me a hint, or maybe point me at some simple examples or tutorials of performing http requests from Homey? Only example I found on github was a fairly complex app that made it difficult for me to understand the basics of the http stuff.

Javascript, I hope. Homey doesn’t run Java :stuck_out_tongue:

If you want to make HTTP requests from Javascript apps, you can use modules like http.min to make life easier.

1 Like

Ah yes, javascript!

That link for http.min is very useful, I had come across it being used but had been unable to find any information about it, however, that link explains it nicely and think I can see what I need to do!

Thanks.

I’m using node-fetch right now, is there a good reason I should switch to http-min? I sometimes see people happily change from node-fetch to http-min, and sometimes the other way around.

With node-fetch I sometimes get a “TypeError: body user already for…” error, and I can’t figure out why. Do yoy think that could be solved by changing to http-min?

TIA!

node-fetch is about 8MB in size, http.min is about 6K in size, so there’s that. It’s possible that node-fetch supports more features, but I doubt that any of them are typically required.

The error you’re getting is likely caused by something in your own code :stuck_out_tongue:

Thanks!

I’ll try the http-min :+1:t3: