…What’s life without an impossible dream…
Featured Post
Arduino Ethernet Shield and Webclient
First thing you do when you get a Ethernet Shield for Arduino (in my case Duemilanove). You will be uploading various example sketches. I was doing the same Ardoino was working flawlessly and then I got stuck in WebClient sketch. I … Continue reading
Power Programming with Tags
Source tagging is very powerful source code navigation system, it beats any state of the art IDE. If you are using Emacs, Vim and TextMate then you can use source tagging for navigation. Here are the few simple steps to … Continue reading
Net neutrality
I was shocked to find that DOT (Department of Technology, India) has blocked major file sharing websites. This clearly is a failure of democracy in india. This proves either india does not care about Internet neutrality or India does not have infra to take … Continue reading
Recent Posts
Grab the net with Arduino
How to access a website with multiple virtual hots from Arduino Ethernet Shield. The problem is if you have used Arduino Ethernet Shield, then you know that you can connect a IP, But if the IP has multiple virtual hosts, it will only connect to default virtual host. If it is commercial shared VPS, You wont be able to make your site default.
Gist is use of HTTP protocol which allows you to define host in your request on virtual host server. Here are the possible headers.
http://en.wikipedia.org/wiki/List_of_HTTP_headers
You should also provide basic debugging info like “User-Agent” etc.
#include <SPI.h>
#include <Ethernet.h>
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 6, 30 };
byte server[] = { ***, ***, 168, 16 }; // Your VPS
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
Client client(server, 80);
String response = "";
void setup() {
Ethernet.begin(mac, ip);
Serial.begin(9600);
// Give the Ethernet shield a second to initialize
delay(1000);
Serial.println("Connecting...");
}
void loop() {
if (!client.available() && client.connect()) {
Serial.println("-- Connected");
// Make a HTTP request:
client.println("GET /bot HTTP/1.0");
client.println("Host: example.com");
client.println("User-Agent: Arduino/Shishir (mail.mastermind [at] gmail.com)");
client.println();
}
if (client.available()) {
char c = client.read();
response.concat(c);
}
if(!client.connected()){
process(response);
//Serial.print(response);
}
if (!client.connected() && reset == 1) {
Serial.println("disconnecting.");
client.stop();
response = "";
delay(1000*10);
}
}
void process(String response) {
Serial.println(response);
}