Last active
May 12, 2017 12:26
-
-
Save su1234567/3ba0f877fd4def0d411064f340b6e022 to your computer and use it in GitHub Desktop.
arduino_twitter_with_dhcp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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