mirror of
https://github.com/KevinMidboe/Arduino.git
synced 2025-10-29 17:40:11 +00:00
Init commit with many years of arduino sketches and projects. I dont know if the esp8266 includes much, but there are also libraries. I hope they dont have crazy automatic versioning through the Arduino IDE.
This commit is contained in:
91
Projects/libraries/Installed_libs/Twitter/Twitter.cpp
Executable file
91
Projects/libraries/Installed_libs/Twitter/Twitter.cpp
Executable file
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
Twitter.cpp - Arduino library to Post messages to Twitter using OAuth.
|
||||
Copyright (c) NeoCat 2010-2011. All right reserved.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*/
|
||||
|
||||
// ver1.2 - Use <string.h>
|
||||
// ver1.3 - Support IDE 1.0
|
||||
|
||||
#include <string.h>
|
||||
#include "Twitter.h"
|
||||
|
||||
#define LIB_DOMAIN "arduino-tweet.appspot.com"
|
||||
|
||||
#if defined(ARDUINO) && ARDUINO < 100
|
||||
static uint8_t server[] = {0,0,0,0}; // IP address of LIB_DOMAIN
|
||||
Twitter::Twitter(const char *token) : client(server, 80), token(token)
|
||||
{
|
||||
}
|
||||
#else
|
||||
Twitter::Twitter(const char *token) : token(token)
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
bool Twitter::post(const char *msg)
|
||||
{
|
||||
#if defined(ARDUINO) && ARDUINO < 100
|
||||
DNSError err = EthernetDNS.resolveHostName(LIB_DOMAIN, server);
|
||||
if (err != DNSSuccess) {
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
parseStatus = 0;
|
||||
statusCode = 0;
|
||||
#if defined(ARDUINO) && ARDUINO < 100
|
||||
if (client.connect()) {
|
||||
#else
|
||||
if (client.connect(LIB_DOMAIN, 80)) {
|
||||
#endif
|
||||
client.println("POST http://" LIB_DOMAIN "/update HTTP/1.0");
|
||||
client.print("Content-Length: ");
|
||||
client.println(strlen(msg)+strlen(token)+14);
|
||||
client.println();
|
||||
client.print("token=");
|
||||
client.print(token);
|
||||
client.print("&status=");
|
||||
client.println(msg);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Twitter::checkStatus(Print *debug)
|
||||
{
|
||||
if (!client.connected()) {
|
||||
if (debug)
|
||||
while(client.available())
|
||||
debug->print((char)client.read());
|
||||
client.flush();
|
||||
client.stop();
|
||||
return false;
|
||||
}
|
||||
if (!client.available())
|
||||
return true;
|
||||
char c = client.read();
|
||||
if (debug)
|
||||
debug->print(c);
|
||||
switch(parseStatus) {
|
||||
case 0:
|
||||
if (c == ' ') parseStatus++; break; // skip "HTTP/1.1 "
|
||||
case 1:
|
||||
if (c >= '0' && c <= '9') {
|
||||
statusCode *= 10;
|
||||
statusCode += c - '0';
|
||||
} else {
|
||||
parseStatus++;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int Twitter::wait(Print *debug)
|
||||
{
|
||||
while (checkStatus(debug));
|
||||
return statusCode;
|
||||
}
|
||||
46
Projects/libraries/Installed_libs/Twitter/Twitter.h
Executable file
46
Projects/libraries/Installed_libs/Twitter/Twitter.h
Executable file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
Twitter.cpp - Arduino library to Post messages to Twitter using OAuth.
|
||||
Copyright (c) NeoCat 2010-2011. All right reserved.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*/
|
||||
|
||||
// ver1.2 - Use <Udp.h> to support IDE 0019 or later
|
||||
// ver1.3 - Support IDE 1.0
|
||||
|
||||
#ifndef TWITTER_H
|
||||
#define TWITTER_H
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <avr/pgmspace.h>
|
||||
#if defined(ARDUINO) && ARDUINO > 18 // Arduino 0019 or later
|
||||
#include <SPI.h>
|
||||
#endif
|
||||
#include <Ethernet.h>
|
||||
#if defined(ARDUINO) && ARDUINO < 100 // earlier than Arduino 1.0
|
||||
#include <EthernetDNS.h>
|
||||
#endif
|
||||
|
||||
class Twitter
|
||||
{
|
||||
private:
|
||||
uint8_t parseStatus;
|
||||
int statusCode;
|
||||
const char *token;
|
||||
#if defined(ARDUINO) && ARDUINO < 100
|
||||
Client client;
|
||||
#else
|
||||
EthernetClient client;
|
||||
#endif
|
||||
public:
|
||||
Twitter(const char *user_and_passwd);
|
||||
|
||||
bool post(const char *msg);
|
||||
bool checkStatus(Print *debug = NULL);
|
||||
int wait(Print *debug = NULL);
|
||||
int status(void) { return statusCode; }
|
||||
};
|
||||
|
||||
#endif //TWITTER_H
|
||||
49
Projects/libraries/Installed_libs/Twitter/examples/SimplePost/SimplePost.pde
Executable file
49
Projects/libraries/Installed_libs/Twitter/examples/SimplePost/SimplePost.pde
Executable file
@@ -0,0 +1,49 @@
|
||||
#include <SPI.h> // needed in Arduino 0019 or later
|
||||
#include <Ethernet.h>
|
||||
#include <Twitter.h>
|
||||
|
||||
// The includion of EthernetDNS is not needed in Arduino IDE 1.0 or later.
|
||||
// Please uncomment below in Arduino IDE 0022 or earlier.
|
||||
//#include <EthernetDNS.h>
|
||||
|
||||
|
||||
// Ethernet Shield Settings
|
||||
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
|
||||
|
||||
// If you don't specify the IP address, DHCP is used(only in Arduino 1.0 or later).
|
||||
byte ip[] = { 192, 168, 2, 250 };
|
||||
|
||||
// Your Token to Tweet (get it from http://arduino-tweet.appspot.com/)
|
||||
Twitter twitter("YOUR-TOKEN-HERE");
|
||||
|
||||
// Message to post
|
||||
char msg[] = "Hello, World! I'm Arduino!";
|
||||
|
||||
void setup()
|
||||
{
|
||||
delay(1000);
|
||||
Ethernet.begin(mac, ip);
|
||||
// or you can use DHCP for autoomatic IP address configuration.
|
||||
// Ethernet.begin(mac);
|
||||
Serial.begin(9600);
|
||||
|
||||
Serial.println("connecting ...");
|
||||
if (twitter.post(msg)) {
|
||||
// Specify &Serial to output received response to Serial.
|
||||
// If no output is required, you can just omit the argument, e.g.
|
||||
// int status = twitter.wait();
|
||||
int status = twitter.wait(&Serial);
|
||||
if (status == 200) {
|
||||
Serial.println("OK.");
|
||||
} else {
|
||||
Serial.print("failed : code ");
|
||||
Serial.println(status);
|
||||
}
|
||||
} else {
|
||||
Serial.println("connection failed.");
|
||||
}
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
#include <SPI.h> // needed in Arduino 0019 or later
|
||||
#include <Ethernet.h>
|
||||
#include <Twitter.h>
|
||||
|
||||
// The includion of EthernetDNS is not needed in Arduino IDE 1.0 or later.
|
||||
// Please uncomment below in Arduino IDE 0022 or earlier.
|
||||
//#include <EthernetDNS.h>
|
||||
|
||||
|
||||
// Sample : Serial port => Twitter gateway
|
||||
// Run this program on Arduino and connect via some Serial port terminal software.
|
||||
// Type a message and hit enter key, and it will be posted to Twitter.
|
||||
// Arduino IDE Serial Monitor is not usable because it doesn't seem able to send Enter key code.
|
||||
|
||||
// Ethernet Shield Settings
|
||||
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
|
||||
|
||||
// If you don't specify the IP address, DHCP is used(only in Arduino 1.0 or later).
|
||||
byte ip[] = { 192, 168, 2, 250 };
|
||||
|
||||
// Your Token to Tweet (get it from http://arduino-tweet.appspot.com/)
|
||||
Twitter twitter("2307428619-jTdwfFJ4r9aYuaYHQ2YeqBWQNOy6nSg6aTRequb");
|
||||
|
||||
|
||||
char msg[141] = "Test01";
|
||||
int len = 0;
|
||||
|
||||
void setup()
|
||||
{
|
||||
delay(1000);
|
||||
Ethernet.begin(mac, ip);
|
||||
// or you can use DHCP for autoomatic IP address configuration.
|
||||
// Ethernet.begin(mac);
|
||||
|
||||
Serial.begin(9600);
|
||||
Serial.print("> ");
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (Serial.available() > 0) {
|
||||
char recv = msg[len++] = Serial.read();
|
||||
if (recv == '\b' || recv == 127) { // Backspace
|
||||
if (len > 1) {
|
||||
len -= 2;
|
||||
Serial.print("\b \b");
|
||||
}
|
||||
}
|
||||
else if (recv == '\r' || recv == '\n') { // send CR/LF to post
|
||||
Serial.print("\r\n");
|
||||
len--;
|
||||
msg[len] = 0;
|
||||
if (len > 0)
|
||||
post();
|
||||
len = 0;
|
||||
Serial.print("\r\n> ");
|
||||
}
|
||||
else if (len > 140)
|
||||
len = 140;
|
||||
else
|
||||
Serial.print(recv);
|
||||
}
|
||||
}
|
||||
|
||||
void post()
|
||||
{
|
||||
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.");
|
||||
}
|
||||
delay(1000);
|
||||
}
|
||||
22
Projects/libraries/Installed_libs/Twitter/keywords.txt
Executable file
22
Projects/libraries/Installed_libs/Twitter/keywords.txt
Executable file
@@ -0,0 +1,22 @@
|
||||
#######################################
|
||||
# Syntax Coloring Map For Twitter
|
||||
#######################################
|
||||
|
||||
#######################################
|
||||
# Datatypes (KEYWORD1)
|
||||
#######################################
|
||||
|
||||
Twitter KEYWORD1
|
||||
|
||||
#######################################
|
||||
# Methods and Functions (KEYWORD2)
|
||||
#######################################
|
||||
|
||||
post KEYWORD2
|
||||
getStatus KEYWORD2
|
||||
checkStatus KEYWORD2
|
||||
wait KEYWORD2
|
||||
|
||||
#######################################
|
||||
# Constants (LITERAL1)
|
||||
#######################################
|
||||
Reference in New Issue
Block a user