How to read data from a blob?

Hi guys!

I’m new to the Electric Imp and I tried to use the Sampler class to get analog data from a sensor with my april devboard. But I think I got stuck with Squirrel now.

In my callback I tried to do this:

function samplesReady(buffer, length)
{
  if(length > 0)
  {
    server.log(buffer);
  }
}

This obviously doesn’t work, because I’m just printing the reference to the blob, not the content. Then I found the method readn(string) and tried this:

function samplesReady(buffer, length)
{
  if(length > 0)
  {
    local signal = buffer.readn('i');
    server.log(signal);
  }
}

This gives me values, I think in the range from 0-65535 from the ADC on my pin.

Am I doing this right? And what other formats can I use with readn(string)?

@cringe -

Had some trouble with this when I started and we discussed in this thread.

http://forums.electricimp.com/discussion/808/adc-noise-when-using-sampler-class#Item_20

I never managed to get the readn(string) command working right and used the buffer[i] syntax to access the values as bytes and create a 16bit value (should actually only be 12 bit). Mind the fact that blobs are Little Endian.

Hope that helps,
Chris