Loading...
Pages: [1]   Go Down
Author Topic: Connecting to more than 1 url.  (Read 213 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 47
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here is the problem. I have a sketch written with Ver 0021. I can't move it to Ver 1 because it uses several 1-wire libraries that have not been updated. It reads 1-wire weather data and also gets local rss weather feeds from Yahoo. This all works great. What I want to do now is connect to another web site ( PushingBox.com) and send a notification AFTER disconnecting from Yahoo. Does anyone know if this is possible. So far I haven't been able to do it. I don't think the old version of the Ethernet library will allow this.

Thanks,
Bill
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 50
Posts: 3448
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't have v0021, but I do have v0022. Hopefully they are close enough. Declare two instances of Client. Just a rough example code snippet here:
Code:
byte server[] = { 1,2,3,4 };
byte server2[] = { 2,3,4,5 };

Client client(server, 80);
Client client2(server2, 80);

  // then in your code:
  // connect to first server
  if (client.connect()) {
    Serial.println("connected server1");
    // Make a HTTP request:
    client.println("GET /search?q=arduino HTTP/1.0");
    client.println();
  }
  else {
    // if you didn't get a connection to the server:
    Serial.println("connection server1 failed");
  }

  // connect to second server
  if (client2.connect()) {
    Serial.println("connected server2");
    // Make a HTTP request:
    client2.println("GET /search?q=arduino HTTP/1.0");
    client2.println();
  }
  else {
    // if you didn't get a connection to the server2:
    Serial.println("connection server 2 failed");
  }
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 57
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


When you are done with the connection you should call client.stop() and client2.stop();
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 47
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks guys. It works perfectly!
Logged

Pages: [1]   Go Up
Print
 
Jump to: