Tweeting Data from Server Log?

Hi there, I’m fairly new to the IMP and I was wondering if I could tweet the data I am receiving in the Device Log? From using one of the examples on the IMP Docs

"// assign hardware.pin5 to a global variable
therm <- hardware.pin5;
// configure pin5 to be an ANALOG_IN
therm.configure(ANALOG_IN);

// these constants are particular to the thermistor we’re using
// check your datasheet for what values you should be using
const b_therm = 3977.0;
const t0_therm = 298.15;

// the resistor in the circuit (10KΩ)
const R2 = 10000.0;

function GetTemp_F() {
local Vin = hardware.voltage();

local Vout = Vin * therm.read() / 65535.0;
local R_Therm = (R2Vin / Vout) - R2;
local ln_therm = math.log(10000.0 / R_Therm);
local temp_K = (t0_therm * b_therm) / (b_therm - t0_therm
ln_therm);
local temp_C = temp_K - 273.15;
local temp_F = temp_C * 9.0 / 5.0 + 32.0;
return temp_F;
}
function poll() {
// Get and log Fahrenheit temperature
local temp = GetTemp_F();
server.log(temp + " F");
// wakeup in 5 seconds and read the value again:
imp.wakeup(5.0, poll);
}

poll()"

Is there any way I can get the agent to forward the data in the device log to a twitter account I have created?

Thanks in advance for any help!

The basic idea is that you collect the data in your device code, send it to an Agent, and the agent makes the tweet.

There is a set of twitter agent classes that you can use to speak to twitter located here: https://github.com/electricimp/reference/tree/master/webservices/twitter

You need to copy the twitter.tweet.agent.nut into your agent code window in the IDE. To get the temperature from your device to the agent, you need to implement a “device.on” function (on the Agent side) for the agent to receive data from the device:

`
_CONSUMER_KEY <- “YourConsumerKey”;
_CONSUMER_SECRET <- “YourConsumerSecret”;
_ACCESS_TOKEN <- “YourAccessToken”;
_ACCESS_SECRET <- “YourAccessSecret”;
twitter <- TwitterClient(_CONSUMER_KEY, _CONSUMER_SECRET, _ACCESS_TOKEN, _ACCESS_SECRET);

device.on( “temperature”, function( temperatureData ) {

twitter.Tweet( temperatureData );

});

`

Then on the device side, you need to change your poll() function to pass the value from the device to the Agent, so that the agent can do the tweet.

function poll() { // Get and log Fahrenheit temperature local temp = GetTemp_F(); agent.send("temperature", temp + " F"); // wakeup in 5 seconds and read the value again: imp.wakeup(5.0, poll); }

So now, instead of logging your temperature to the IDE, you tweet it. You can change the function to log and tweet at the same time if that will help your debugging effort.

thanks for your help! I got it set up perfectly!

https://twitter.com/impprojectdemo

Many thanks again for your help deonsmt!

Now that you have that going, you can try the other web services that will allow you to graph your data in real time like Xively and Plotly. There are others I haven’t tried like open.sen.se and att m2m. The mechanism is the same - move data from the device to the Agent to the web service.