Pasos a aseguir
Las librerias de Microtweet de Codeplex, aquí
Crear una nueva cuenta de twitter.
Regístrese nueva aplicación según las instrucciones. Agregar 4 claves para el código.
Se usara un ssnsor de 1 hilo S1820 (de la parte posterior de Java material Tini en 2000/01. Obsoleta DS1820, pero funciona bien)1
Tambien se usa un pulsador para realizar elenvio de tweets
Cargue este codigo en su netduino , asegurese que este est coenctado a Internet y Pulse el botón: esto , leera la temperatura,y enviara tweets.
A continuación el codigo para nuestro Netduino:
003 |
using System.Net.Sockets; |
004 |
using System.Threading; |
005 |
using Microsoft.SPOT; |
006 |
using Microsoft.SPOT.Hardware; |
007 |
using SecretLabs.NETMF.Hardware; |
008 |
using SecretLabs.NETMF.Hardware.NetduinoPlus; |
009 |
using Komodex.NETMF.MicroTweet; |
010 |
using Microsoft.SPOT.Net.NetworkInformation; |
011 |
using CW.NETMF.Hardware; |
013 |
namespace TweetButtonTest |
017 |
private const string consumerKey = "KeyGoesHere" ; |
018 |
private const string consumerSecret = "ItsASecret" ; |
019 |
private const string userToken = "InsertCoin" ; |
020 |
private const string userSecret = "Shh...DontTellAnyone" ; |
022 |
private const string ntpServer = "time-a.nist.gov" ; |
024 |
private OutputPort led = null ; |
025 |
private TwitterClient twitterClient = null ; |
026 |
private OneWire oneWire; |
028 |
public static void Main() |
036 |
NTP.UpdateTimeFromNTPServer(ntpServer); |
038 |
twitterClient = new TwitterClient(consumerKey, consumerSecret, userToken, userSecret); |
040 |
oneWire = new OneWire(Pins.GPIO_PIN_D1); |
041 |
led = new OutputPort(Pins.GPIO_PIN_D13, false ); |
043 |
Button button = new Button(Pins.GPIO_PIN_D0); |
044 |
button.Released += new NoParamEventHandler(button_Released); |
046 |
Thread.Sleep(Timeout.Infinite); |
049 |
void button_Released() |
053 |
float temperature = GetTemperature(); |
054 |
string msg = "Today I'm tweeting the temperature from an DS1820. It's " +temperature+ "C #netdunio" ; |
057 |
bool tweetSent = twitterClient.SendTweet(msg); |
073 |
private void FlashLed( int flashCount) |
075 |
while (flashCount-- > 0) |
084 |
private float GetTemperature() |
087 |
oneWire.WriteByte(OneWire.SkipRom); //All devices |
088 |
oneWire.WriteByte(DS1820.ConvertT); //Do convert |
089 |
Thread.Sleep(750); //Wait for conversion |
092 |
oneWire.WriteByte(OneWire.SkipRom); //All devices |
093 |
oneWire.WriteByte(DS1820.ReadScratchpad); //Read data |
095 |
//Read the first two bytes - tempLow and tempHigh |
096 |
byte tempLow = oneWire.ReadByte(); |
097 |
byte tempHigh = oneWire.ReadByte(); |
098 |
return DS1820.GetTemperature(tempLow, tempHigh); |
Fuente:http://nerduino.wordpress.com/category/code/