Mixed data agent.send issue

This is strange. I am collecting data in the device and sending it to the agent. The agent is collecting and retaining the data.
It worked for a while and then one of my edits caused the output at the agent to change to this:
(array : 0x7f99b8c8abe0)(array : 0x7f99b8c8abe0)(array : 0x7f99b8c8abe0)(array : 0x7f99b8c8abe0)(array : 0x7f99b8c8abe0)(array : 0x7f99b8c8abe0)(array : 0x7f99b8c8abe0)(array : 0x7f99b8c8abe0)(array : 0x7f99b8c8abe0)

The array seems to be ok at the device

I tried breaking down the function to this
DEVICE
`function loop()
{
local d = date();
local dday = d.day;
local dhour = d.hour-5;//corrects for UTC device time
if (dhour < 0) {
dhour += 24;//corrects for UTC device time
dday -= 1;//corrects the day count for UTC device time
}
local d1 = 1
local d2 = 2
local d3 = “dave"
local senddata = d.wday+”,"+dhour+":"+d.min+",C#,"+d1+","+d2+","+d3+","
server.log (“device=”+senddata);
agent.send(“comms”,senddata)
imp.wakeup (5,loop);
}

loop();`

AGENT
`save <- “”

device.on (“comms”, function (data){
save = save + data;
server.log (“agent=”+save+“s not here”)
})`

But of course this works perfectly returning the following:
2015-08-04 10:02:02 UTC-5 [Device] device=2,10:2,C#,1,2,dave, 2015-08-04 10:02:02 UTC-5 [Agent] agent=2,10:2,C#,1,2,dave, is not here 2015-08-04 10:02:07 UTC-5 [Agent] agent=2,10:2,C#,1,2,dave,2,10:2,C#,1,2,dave, is not here 2015-08-04 10:02:07 UTC-5 [Device] device=2,10:2,C#,1,2,dave,

Any ideas are welcome

After digging further this seems to be caused by declaring the variable as a string or an array.Check this out…
`Device
function loop()
{
local d = date();
local dday = d.day;
local dhour = d.hour-5;//corrects for UTC device time
if (dhour < 0) {
dhour += 24;//corrects for UTC device time
dday -= 1;//corrects the day count for UTC device time
}
local senddata = d.wday+","+dhour+":"+d.min+":"+d.sec+","
server.log (“device=”+senddata);
agent.send(“comms”,senddata)
imp.wakeup (15,loop);
}

loop();
`

`Agent
data_store <-[]

device.on (“comms”, function (data){
//data_store.append(data);
data_store = data_store+data;
server.log (“agent =”+data_store);
})`

Result 2015-08-05 11:09:09 UTC-5 [Status] Device connected 2015-08-05 11:09:09 UTC-5 [Device] device=3,11:9:9, 2015-08-05 11:09:09 UTC-5 [Agent] agent =(array : 0x7f99d161c360)3,11:9:9, 2015-08-05 11:09:24 UTC-5 [Device] device=3,11:9:24, 2015-08-05 11:09:24 UTC-5 [Agent] agent =(array : 0x7f99d161c360)3,11:9:9,3,11:9:24, 2015-08-05 11:09:39 UTC-5 [Device] device=3,11:9:39, 2015-08-05 11:09:39 UTC-5 [Agent] agent =(array : 0x7f99d161c360)3,11:9:9,3,11:9:24,3,11:9:39, 2015-08-05 11:09:54 UTC-5 [Agent] agent =(array : 0x7f99d161c360)3,11:9:9,3,11:9:24,3,11:9:39,3,11:9:54, 2015-08-05 11:09:54 UTC-5 [Device] device=3,11:9:54, 2015-08-05 11:10:10 UTC-5 [Agent] agent =(array : 0x7f99d161c360)3,11:9:9,3,11:9:24,3,11:9:39,3,11:9:54,3,11:10:9,
I do not understand the mechanism that makes it display like this

If I swap the commented line to use the append instead it returns this
2015-08-05 11:14:00 UTC-5 [Agent] agent =(array : 0x7f99d149fad0) 2015-08-05 11:14:00 UTC-5 [Status] Device connected 2015-08-05 11:14:00 UTC-5 [Device] device=3,11:14:0, 2015-08-05 11:14:15 UTC-5 [Agent] agent =(array : 0x7f99d149fad0) 2015-08-05 11:14:15 UTC-5 [Device] device=3,11:14:15,

If change the data_store as “” and swap to the non-append line, I get this
2015-08-05 11:12:09 UTC-5 [Status] Device connected 2015-08-05 11:12:09 UTC-5 [Device] device=3,11:12:9, 2015-08-05 11:12:09 UTC-5 [Agent] agent =3,11:12:9, 2015-08-05 11:12:24 UTC-5 [Device] device=3,11:12:24, 2015-08-05 11:12:24 UTC-5 [Agent] agent =3,11:12:9,3,11:12:24, 2015-08-05 11:12:39 UTC-5 [Device] device=3,11:12:39, 2015-08-05 11:12:39 UTC-5 [Agent] agent =3,11:12:9,3,11:12:24,3,11:12:39,

It would seem that my issue is in converting the data in an array to something that can be displayed or emailed (some kind of text format). If this is not possible, I could process the array out to capture the data instead.

FYI, I have tried the .tostring in the server.log and that does not work either

Squirrel is loosely typed, and will automatically convert between some types for certain operations.

In your code, you’re trying to add a string to an array, which Squirrel interprets as concatenating two strings together (you can’t add something to an array with +, but you can add something to a string with +).

I’m not really certain what you’re trying to accomplish - if you could clarify that, I can probably give some more guidance :slight_smile:

Is this what you’re trying to do:

Device:
`function loop()
{
local d = date();
local dday = d.day;
local dhour = d.hour-5;//corrects for UTC device time
if (dhour < 0) {
dhour += 24;//corrects for UTC device time
dday -= 1;//corrects the day count for UTC device time
}
/********** Removed the last comma from this line **********/
local senddata = d.wday+","+dhour+":"+d.min+":"+d.sec
server.log (“device=”+senddata);
agent.send(“comms”,senddata)
imp.wakeup (1,loop);
}

loop();
`

Agent:
`data_store <-[]

device.on (“comms”, function (data){
data_store.append(data);
server.log ("agent = "+ http.jsonencode(data_store));
})`

Thanks for the help. You are right; I didn’t explain myself very well

I am collecting various data (analog/binary/time/date) on the device and transferring that data to the agent for persistent storage and processing.

I’m trying to store data in an array because I need a statistical analysis on the data. The .array functions seem the simplest.

Right now I am trying to do this with a single agend.send and a comma delimited data set. I was trying to build a platform that would be expandable if other data was required and again, an array seemed easiest.

I would like to display the raw values in various places (email body through mailgun, on the web page, and in server.log). Theoretically, displaying the array is a stop-gap measure to allow me to verify the statistical analysis code I am about to write.

After catching your meaning it seems I could either parse the data back on the agent side and convert into separate arrays, or agent.send each data type on its own and collect them up as needed on the other side. The former may be the most productive.