Skip to content

Instantly share code, notes, and snippets.

@hideack
Created October 17, 2020 05:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hideack/be81e05dd6fa7846ae57dad19a723189 to your computer and use it in GitHub Desktop.
Save hideack/be81e05dd6fa7846ae57dad19a723189 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = {0x00,0xAA,0xBB,0xCC,0xDE,0x02}; // イーサシールドのMacアドレス記入
char hostname[] = "***.sqale.jp"; // 契約中のレンタルサーバのホスト名
char serverName[256];
char httpHeaderHost[256];
EthernetClient client;
void setup()
{
sprintf(serverName, "%s", hostname);
sprintf(httpHeaderHost, "Host: %s", hostname);
Serial.print("Target host:");
Serial.println(hostName);
Serial.begin(9600);
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
for (;;);
}
Serial.print("My IP address: ");
for (byte n=0; n<4; n++) {
Serial.print(Ethernet.localIP()[n], DEC);
Serial.print(".");
}
Serial.println();
delay(1000);
Serial.println("connecting...");
if (client.connect(serverName, 80)) {
Serial.println("connected");
client.println("GET /hoge/foo HTTP/1.1");
client.println("User-Agent: aruduino");
client.println(httpHeaderHost);
client.println();
} else {
Serial.println("connection failed");
}
}
void loop()
{
if (client.available()) {
char c = client.read();
Serial.print(c);
}
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
while(1){}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment