Running Pings

Okay so I just bought an april board and an imp :slight_smile: While messing around with the ping pong example I was trying to run something that can give me and average ping along with what the current ping is. so when it pings 10 the average is 10 so it should look like 10ms AVG:10ms then when another ping is run say… 0 then the ping would be 0ms AVG:5ms but happening per second. I am not sure how this can be done and on top of that i need to ping multiple servers, ap’s, etc. I have a base idea but am not that familiar with squirel and also do not know if and what would need to be agent side and what should be device side. Please give input as i will be working on this until I get my prospected results which should take some time :slight_smile: but any feedback or sample code would be nice. this is just for my consumer use nothing for a business so no credit or anything will be needed on anyones part unless you want it :slight_smile: Thanks, Beowulf

Could you post your code?

` //When we get a “pong” message from the agent
agent.on(“pong”, function(startMillis) {
//Current time
local endMillis = hardware.millis();
//Difference of time or "ping"
local diff = endMillis - startMillis;
//Server Log

//Wakeup time to ping again
imp.wakeup(2.0, ping);

//Average ping test
local tot = 0;
local cur = 0;
local count = 0;
local avg = 0;

if (count < 1) {
    cur = diff;
    tot = cur + tot;
    avg = tot / cur;
    count++;

    server.log("Average is:" + avg);
}

});
//Pings the server
function ping() {
//Send a ping message with the current millis counter
agent.send(“ping”, hardware.millis());
}
//Start Ping-Pong
ping();`
This is just my recent idea I’m playing with.

I was thinking maybe using some local variables but any help would be nice to point me in a direction. Remember…, relatively new to squirrel, plus I should add I havent had internet for at least a year so I am behind the times and have recently started working with a microwave isp. Things should get fun with this imp from now on :slight_smile:

I wrapped you code in a code tag (the C icon in the format bar above the entry box) - makes it a bit easier to read :slight_smile:

You probably want to do a running average of the last x pings rather than a true average, otherwise your data is going to become very boring very quickly.

Maybe all of the pings within the last minute (or the last 30 pings if you’re sending them every 2 seconds).

No I want a live feed of pings at the moment when I look at what my device (possibly lcd or something of that sort) to display of what the ping is, then the average. I could do them in lumps of say 250-1000 but I would still want that 250-1000 be live. Also code wise I was thinking of using an array maybe but I don’t know if that is the best way to go about this. I’ve already gotten interesting results the way this thing uses its math… sometimes when I set it to divide it still adds or multiplies… Can someone explain exactly how this thing runs its code and wether or not I even need to make a loop?

Sorry, I was talking about for the average ping. If you take the lifetime average, then after a couple hundred pings, you’re not going to see much movement in your avg ping time graph.

When have you asked Squirrel to divide and it adds or multiplies? Do you have a code example by chance?

Are you looking for an explanation as to how the code you posted works?

I know after a couple hundred pings it would be standard but thats what I am looking for. Not much change… The set-up here is getting cleaner and cleaner (at my work) and I would like to keep track of all of our AP’s at the same time with pings and then average pings within the set amount I please. At the code portion, no, I know how the code works I was just wondering how I can make it work :P, but yes let me try to rework that code into it if I can remember it.