Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
arduino_twitter_with_dhcp
#if defined(ARDUINO) && ARDUINO > 18 // Arduino 0019 or later
#include <SPI.h>
#endif
#include <Ethernet.h>
//#include <EthernetDNS.h> Only needed in Arduino 0022 or earlier
#include <Twitter.h>
byte mac[] = { 0x**, 0x**, 0x**, 0x**, 0x**, 0x** }; //**を編集
// 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):
EthernetClient client;
Twitter twitter("*********************"); //tokenコード
char msg[] = "Hello, World! I'm Arduinoooooo!";
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
// this check is only needed on the Leonardo:
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
//DHCPサーバからIPアドレスをゲット
// start the Ethernet connection: 失敗したときは戻り値がゼロ
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
for(;;)
;
}
// print your local IP address:
Serial.print("My IP address: ");
for (byte thisByte = 0; thisByte < 4; thisByte++) {
// print the value of each byte of the IP address:
Serial.print(Ethernet.localIP()[thisByte], DEC);
Serial.print(".");
}
Serial.println();
//twitter投稿
delay(1000);
Serial.println(Ethernet.localIP());
Serial.println("connecting ...");
if (twitter.post(msg)) {
int status = twitter.wait();
if (status == 200) {
Serial.println("OK.");
} else {
Serial.print("failed : code ");
Serial.println(status);
}
} else {
Serial.println("connection failed.");
}
}
void loop()
{
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment