last day (14 days later) » 

1:18 PM
0
Q: IoT module GET request in Java

MastariusI'm trying to read a JSON response from a RESTful webserver running on an IoT module (Advantech WISE-4012). According to the documentation, any GET request should be made in this form GET /ai_value/slot_0/ch_0 Any Java implementation of GET requests (Java libraries, Apache etc.), anyway, appen...

 
Check the response headers and/or body and see if there's any error message?
 
@DarshanMehta i added the response and the source message on my post. Thank you
 
Can you try using curl as well, from command line?
 
@DarshanMehta i'm on windows environment but i'll figure out how to do something like that. Any suggestion?
 
1:18 PM
@DarshanMehta i tried using curl as mentioned. curl -i -H "Accept: application/json" -H "Content-Type: application/json" -X GET http://192.168.0.14/ai_value/slot_0/ch_0 gives me always the same response: HTTP/1.0 Bad request 400 and same response headers as the other tests. I'm wondering why sometimes it does work by calling it on chrome, otherwise i'd assume that my device is not working.
 
Could you point me to the documentation of this API?
 
Thank you very much for your help: this is the documentation (bb-elec.com/Products/Manuals/WISE-4000-Manual.pdf) for the product i'm using (WISE-4012). In particular, page 125 refers to the built-in Restful web service and the specific requests to make in order to get analog or digital input values. Unfortunately it's not a very rich documentation, but if you see any alternative to my approach please let me know. Thanks again
I get a similar output compared to the documentation only when calling from Google chrome, i can post a screenshot if needed.
 
1:40 PM
Can you try 10.0.0.1/ai_value/slot_0 in the google chrome and see if it returns anything?
 
That's not the correct ip actually, it's like that only when using the device in Access point mode. In this case i'm using infrastructure mode connecting to an existing ap. I checked and the address is correct as you see in my posts (in fact, using 192.168.0.14 i can connect successfuly to the admin panel on any browser, but only get json data on chrome and errors anywhere else).
 
just wanted to make sure slot_index is actually an index and hence, you need to pass slot_0 and not slot_index literally..
If that is fine then, could you open dev tools in chrome (ctrl + shift + i) and check the request headers in 'Network' tab?
 
There are 4 slots so i'm pretty sure that it refers to the actual index. Anyway i just tried and for everything different from a "correct" request, i get {"Err": 404, "Msg": "404 File not found"}. Otherwise, error 400 returns {"Err": 1000, "Msg": ""} this generic error. Yes, i will try now to check the request headers
This is a working request from chrome with devtools on network tab: imgur.com/jUJ57zt
While trying at the same time, Internet explorer keeps returning Error 400. At this point i'm afraid the software is bugged and there's no way out of this situation
 
2:00 PM
When IE rerturns 400, chrome works fine?
I can't think of anything else except headers.. (Maybe IE and/or your app does not pass accept header)?
If both IE and chrome stop working at the same time then yes, the software is buggy..
 
When Chrome stops working, i noticed that logging into the device's admin panel makes it working again (it may be some kind of internal timeout?). Anyway, in all the cases, the only software i was able to make it working was chrome. Logging into the device doesn't make it working for IE or any other thing (curl, apache java library etc..)
I can only think of headers and that thing i mentioned about HTTP/1.1 at the end of GET request (but i cannot try since all software sends GET request like that).
Just to a complete view, this is a failed request on Chrome: http://imgur.com/a/MgZSu
I made it by rebooting the device. I confirm that logging into its panel make it working again for an arbitrary time
 
Well, in that case, it might be User-Agent header. Try copying the header from chrome dev toolbar and send it with postman request and/or curl?
Yes, if it starts working after logging in then there must be some sort of session management.
I can see some documentation on compatilibity on page 50, maybe worth having a look?
 
I'll try right now
 
Looks like it's cookie header
It gets expired and you then get 400
 
2:17 PM
Yes, i noticed now. After logging into the device, the value changes and it start working again. On the working screenshot you have a value, the same Cookie:adamsessionid seems not to be working after a reboot and logging into the device changes it and makes it working again.
How can we make it working on any other device? Is there a solution in your opinion?
Also, i tried logging into IE and after logging into the panel, it seems to be returning a json successfuly also there. It's a session problem for sure
 
I am just trying to search in the documentation..
Looks like there is undocumented session management somewhere in the device..
Page 53 states the default timeout of 720 seconds (12 minutes) and it looks like session times out despite of activities in last 12 minutes. So, I believe you need to implement session management into your service layer (i.e. if it returns 400, login again and retry the same request)..
 
I really don't know how i could implement the authentication on an admin panel into a java software, but it's really strange that on the JSON Rest documentation this is not mentioned or handled in any manner. I guess next time i'll read documentation before buying stuff
The default timeout can be changed anyway, but still i don't know any simple solution to this beside setting the session manually and keeping it refreshing before the timeout (that would not be a problem, i'm planning to poll data every 30 seconds, but i need to make it working first)
 
2:43 PM
Can you not always make login call before making any other call via rest API?
 
I will try to see what kind of authorization it requires and see if i can use it on the headers on every call
I'd like to update you: using basic auth on Postman and root access, it's working. Now i need to add these headers to the java call and probably it's working again. Thanks to your researches and the effort you put on this thing i can probably make it working. When it's done, if you want to make a short response on my post i will mark it as a correct answer and give you credit for it (as it should be). Thanks again
 
Glad it's working fine now..
Sure, will do.
Done, let me know if anything needs adding :)
 
3:14 PM
Looks good! I confirm you that adding an header to my http request, containing Authorization Basic cm9vdDowMDAwMDAwMA== (which is actually the username, password encoded) made it working
Thanks again for your help
It was really precious
 

last day (14 days later) »