0

[SOLVED] Get API from several hosts
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

[SOLVED] Get API from several hosts

by theophile on Sat Aug 24, 2019 3:18 am

Hello,

Is it possible to get API data ( in json) from two different hosts ?

I am working on an ESP 8266 project which compiles several data from two API host :

- astrological data of moon and sun from : https://ipgeolocation.io
- Weather data from : https://openweathermap.org

I already made the code to get the weather data of one specifics location and parse it with json.
I now need to get data from the astrological host in order to compile all data/result from both hosts, to control lights / servo etc..with my ESP.

If possible to do it, I do not know form where to start as I already define the "host" for one website in my program..

FYI, I attached my program (so far coded)


Thanks for your help !
Théo
Attachments
IML_V2_for_ada_q.ino
(3.88 KiB) Downloaded 8 times

theophile
 
Posts: 9
Joined: Fri Feb 15, 2019 6:25 am

Re: Get API from several hosts

by adafruit_support_mike on Sun Aug 25, 2019 1:06 pm

Sure.. each request for JSON data is independent of the other, so it’s just a matter of writing one program that does both requests.

adafruit_support_mike
 
Posts: 58799
Joined: Thu Feb 11, 2010 2:51 pm

Re: Get API from several hosts

by Rameez on Tue Aug 27, 2019 8:36 am

Hi Theophile,

I am talking from https://ipgeolocation.io. I have seen your code and made a few changes in it.
For IP geolocation Astronomy API, I have connected it to our Singapore node directly because our main load balancer requires https parameter and does not allow a non-https connection. To make https connection, you'll have to configure CA (Certification Authority) first on Arduino. Take reference from here https://techtutorialsx.com/2017/11/18/e ... et-request.

If you still have any problem, feel free to contact me at rameez@ipgeolocation.io.


Regards,
Rameez
Customer Success Executive.
https://ipgeolocation.io
Attachments
IML_V2_for_ada_q.ino
Modified Code
(4.56 KiB) Downloaded 9 times

Rameez
 
Posts: 4
Joined: Tue Aug 27, 2019 7:25 am

Re: Get API from several hosts

by theophile on Tue Aug 27, 2019 12:19 pm

Hi Rameez

Thanks for your answer !
I was quiet struggling before to get the point with the CA..

I updated the code following your recommendation (In accordance for ESP 8266).
However, I don t know how to get the CA verified while sending a request to the server...?
I tried that way (But not successful) :

client.print(String("GET/astronomy?apiKey=54021129fae84cbf95bd9b43aa100bf4&lat=-27.4748&long=153.017", root_ca) + "HTTP/1.1\r\n" +
"Host: " + host2 + "\r\n" +
"User-Agent: BuildFailureDetectorESP8266\r\n" +
"Connection: close\r\n" +
"\r\n"

Do you have any Idea ?
Attached my program updates

Many thanks !
Théo
Attachments
IML_V4_ada.ino
(6.66 KiB) Downloaded 7 times

theophile
 
Posts: 9
Joined: Fri Feb 15, 2019 6:25 am

Re: Get API from several hosts

by Rameez on Wed Aug 28, 2019 6:35 am

Hi Theophile,

We have no hardware to test CA on a surety basis.
But check your code by using our Singapore node "sg-api.ipgeolocation.io". After that, you will not need any CA. Because our Singapore node allows HTTP connection and the HTTP connection doesn't need CA.


Regards,
Rameez

Rameez
 
Posts: 4
Joined: Tue Aug 27, 2019 7:25 am

Re: Get API from several hosts

by theophile on Wed Aug 28, 2019 8:49 am

Hi Ramez

Thanks again for you help !

It works now on ESP8266. Getting and display JSON data from two different http clients.

Attached the updated version FYI.

++
Théo
Attachments
IML_V6_ada.ino
(2.58 KiB) Downloaded 5 times

theophile
 
Posts: 9
Joined: Fri Feb 15, 2019 6:25 am

Re: Get API from several hosts

by Rameez on Wed Aug 28, 2019 8:57 am

It's my pleasure Theophile!
If you face any problem further regarding our product, I am just an e-mail away.


Regards,
Rameez
Customer Success Executive
rameez@ipgeolocatiom.io
https://ipgeolocation.io/

Rameez
 
Posts: 4
Joined: Tue Aug 27, 2019 7:25 am

Re: [SOLVED] Get API from several hosts

by theophile on Mon Sep 09, 2019 9:47 am

Hi Rameez,

I might have one more question / request to finalized my program :
Is there a way to get directly from ipgeolocation the moonRise and moonSet in unix timestamp instead of HH:MM?

I already find a way to convert it to unix format but after testing my program for some days I am facing some incoherence depending on the day of the request is made to the server (differing from the place on earth).

Thanks,
Théophile

theophile
 
Posts: 9
Joined: Fri Feb 15, 2019 6:25 am

Re: [SOLVED] Get API from several hosts

by Rameez on Wed Sep 11, 2019 12:07 pm

Hi Theophile,

How are you?
Sorry for the late reply...
Our API doesn't provide moonrise and moonset in Unix timestamp.
If you need further help regarding our API, please contact me at rameez@ipgeolocation.io for instant response.

Regards,

Rameez
 
Posts: 4
Joined: Tue Aug 27, 2019 7:25 am

Please be positive and constructive with your questions and comments.