Agent Message Receiving / Twitter API Question

Hello, first time poster here. As part of a project I am attempting to use the Twitter API to send a tweet when a certain appliance at my home is turned on. As part of the initial testing, I wanted to make sure I could send a message with the current hour to the agent, then tweet a message involving the current hour. The following code produces no errors, yet for some reason does not work (no tweet appears and no message appears in the server log).

Any help people could provide would be appreciated.

Thanks

My Agent Code is:

`#require “Twitter.class.nut:1.2.1”

//The actual keys have been omitted for the sake of this post
const API_KEY = “XYZ”;
const API_SECRET = “XYZ”;
const AUTH_TOKEN = “XYZ”;
const TOKEN_SECRET = “XYZ”;
twitter <- Twitter(API_KEY, API_SECRET, AUTH_TOKEN, TOKEN_SECRET);

function mesHandler(now){
return function(){
server.log(now.hour.toString());
twitter.tweet("Hello World. It is hour: " + now.hour.toString());
};
}

device.on(“mes”, mesHandler);`

My device code is:

`device_switch <- hardware.pin1;

device_switch.configure(DIGITAL_OUT,0);

state <- 0;

function send_tweet(){
local now = date();

agent.send("mes", now);

}

function turn_on(){
state = 1 - state;
device_switch.write(state);

send_tweet();
imp.wakeup(60.0, turn_on);

}

turn_on();
`

You’re returning a function in your handler, rather than executing it. Try passing the function directly to device.on:
device.on("mes", function(){ server.log(now.hour.toString()); twitter.tweet("Hello World. It is hour: " + now.hour.toString()); })

…or doing what you want to do in mesHandler:
`
function mesHandler(now){
server.log(now.hour.toString());
twitter.tweet("Hello World. It is hour: " + now.hour.toString());
}

device.on(“mes”, mesHandler);`