Go Down

Topic: Accessing HTTPS from wifi interface (Read 1 time) previous topic - next topic

jpremor

Guys,

i'm using the HttpClient to access some data on the web. In this case specifically i'm getting weather information from open weather.  

Code: [Select]

String getWeatherData()
{
 HttpClient client;
 char charstep = 0;
 typedef enum {STEP_TEMP, STEP_HUMI} TValueStep;
 
 static const char openWeatherLink[] = "http://api.openweathermap.org/data/2.5/weather?q=Stevensville&mode=json&units=metric";
 
 TValueStep valuestep = STEP_TEMP;
 String tempValue = "";
 String humidValue = "";
 client.get(openWeatherLink);

 while (client.available()) {
   char c = client.read();
   if ((charstep == 0) & (c == 't')) {
      charstep++;
      valuestep = STEP_TEMP;
   }
   else if ((charstep == 0) & (c == 'h')) {
      charstep++;
      valuestep = STEP_HUMI;
   }
   // read temp
   else if (valuestep == STEP_TEMP) {
     if ((charstep == 1) & (c == 'e')) charstep++;
     else if ((charstep == 2) & (c == 'm')) charstep++;
     else if ((charstep == 3) & (c == 'p')) charstep++;
     else if ((charstep == 4) & (c == '"')) charstep++;
     else if ((charstep == 5) & (c == ':')) charstep++;
     else if (charstep == 6) {
       if ((c != ',') && (c != '}')) tempValue += c;
       else charstep++;
     }
     else charstep = 0;
   }
   // read humidity
   else if (valuestep == STEP_HUMI) {
     if ((charstep == 1) & (c == 'u')) charstep++;
     else if ((charstep == 2) & (c == 'm')) charstep++;
     else if ((charstep == 3) & (c == 'i')) charstep++;
     else if ((charstep == 4) & (c == 'd')) charstep++;
     else if ((charstep == 5) & (c == 'i')) charstep++;
     else if ((charstep == 6) & (c == 't')) charstep++;
     else if ((charstep == 7) & (c == 'y')) charstep++;
     else if ((charstep == 8) & (c == '"')) charstep++;
     else if ((charstep == 9) & (c == ':')) charstep++;
     else if (charstep == 10) {
       if ((c != ',') && (c != '}')) humidValue += c;
       else charstep++;
     }
     else charstep = 0;
   }
 }
 return (humidValue + "/" + tempValue);
}


The code above is working fine and feel free to use it :). Just change the word "Stevensville" to your city in the link.

The problem now is when i try to do something similar with google calendar that is a HTTPS connection.
Using HttpClient dont work at all. I noticed that Ethernet interface libraty have support for HTTPS but not Wifi.
Any idea how to do solve it?

Thanks!

federicofissore

It should work just fine (and there is no difference between Ethernet and Wifi on the Yun because they are both manged by linux)
Can you post the sketch?

jpremor

I solved  my problem using "curl".
And httpclient dont work with https.

amlo13

I'm interested in this project! You just need to use this function in the loop, after having a connection to a WIFI network? Can you provide the full skecth?

Many thanks!

Go Up