Log not recording agent events

At times, the agent is not logging events ( in IDE ) . The html request is being handled and a return response is sent to browser. But the log shows no activity. Also, this is coupled with the device not reponding to the agent. Is this a bug ? Most of the time it works but I am worried about this intermittent behaviour. Reload and build works fine and is logged. This is using provided example to turn on / off a LED.

What browser?

In latest chrome.

That’s quite strange, can you provide the code you’re running? Logging display is totally unrelated to the device<>agent comms.

If you reload the page, do the missing logs appear?

Hi, It is just when the device is not responding, the log does not show the brower based request at all.
And I would expect the device to have great connectivity. it is 1 meter from the wifi access point.
Here is the code:


// Check 1
//device.onconnect(function() { server.log(“Device connected to agent”); });
//device.ondisconnect(function() { server.log(“Device disconnected from agent”); });
// Check 2
// Log device connection status :
connectedString <- “offline”;

if (device.isconnected()) {
connectedString = “online”;

server.log("The device is " + connectedString);

// Main Agent Code
// Log the URLs we need
server.log("Turn arena_light On: " + http.agenturl() + “?arena_light=1”);
server.log("Turn arena_light Off: " + http.agenturl() + “?arena_light=0”);

function requestHandler(request, response) {
try {
// Check if the user sent arena_light as a query parameter
if (“arena_light” in request.query) {
// If they did, and arena_light=1… set our variable to 1
if (request.query.arena_light == “1” || request.query.arena_light == “0”) {
// Convert the arena_light query parameter to an integer
local arena_lightState = request.query.arena_light.tointeger();

            // Send "set.arena_light" message to device, and send arena_lightState as the data
            device.send("set.arena_light", arena_lightState); 
    if ("ring_light" in request.query) {
        // If they did, and ring_light=1.. set our variable to 1
        if (request.query.ring_light == "1" || request.query.ring_light == "0") {
            // Convert the ring_light query parameter to an integer
            local ring_lightState = request.query.ring_light.tointeger();

            // Send "set.ring_light" message to device, and send ring_lightState as the data
            device.send("set.ring_light", ring_lightState); 

    // Send a response back to the browser saying everything was OK.
    response.send(200, "OK 3 Really ?");
} catch (ex) {
    response.send(500, "Internal Server Error: " + ex);

// RAK ring_light

// Register the HTTP handler to begin watching for HTTP requests from your browser

------------------And the Device  --------------

// Check 1
//server.log(“Device online”);
//imp.wakeup(5.0, function() { server.sleepfor(20.0); });

// Main Device code
// Create a global variabled called ‘arena_light’ and assign the ‘pin9’ object to it
// The <- is Squirrel’s way of creating a global variable and assigning its initial value
arena_light <- hardware.pin9;
ring_light <- hardware.pin8;

// Configure ‘arena_light and ring_lignt’ to be a digital outputs with a starting value of digital 0 (low, 0V)
arena_light.configure(DIGITAL_OUT, 0);
ring_light.configure(DIGITAL_OUT, 0);

// Function called to turn the arena_light on or off
// according to the value passed in (1 = on, 0 = off)

// Arena
function setarena_lightState(state) {
server.log("Set arena_light to state: " + state);

// Register a handler for incoming “set.led” messages from the agent
agent.on(“set.arena_light”, setarena_lightState);

// Ring
function setring_lightState(state) {
server.log("Set ring_light to state: " + state);

// Register a handler for incoming “set.led” messages from the agent
agent.on(“set.ring_light”, setring_lightState);

--------------------- LOG Extract ------------------

2015-11-23 20:42:31 UTC+1 [Agent] The device is offline
2015-11-23 20:42:31 UTC+1 [Agent] Turn arena_light On: https://agent.electricimp.com/myid?arena_light=1
2015-11-23 20:42:31 UTC+1 [Agent] Turn arena_light Off: https://agent.electricimp.com/myid?arena_light=0

1m is likely too close to the AP, you’re probably saturating the receiver. What does imp.getrssi() report? If it’s above around -25dBm then move it further away.

If Hugo’s suggestion doesn’t work for you, you could scrutinise what data you receive in the http request and reinstate your handlers for device.onconnect and device.ondisconnect.

You would see the output that you’re getting if the http requests failed to receive either a 1 or a 0.

Your code is hard to read when it’s not in a code block. It will help others review it if you wrap it like so:

// Check 1
device.onconnect(function() { server.log("Device connected to agent"); });
device.ondisconnect(function() { server.log("Device disconnected from agent"); });