0

I am trying to process binary data retrieved from a Davis weather station via their web server.

I do this using a script attached to a Google Apps Spreadsheet.

var lResponse = UrlFetchApp.fetch(lWLDataUrl);
var lContentBytes = lResponse.getAs('application/octet-stream').getBytes();

The data returned by Weatherlink is composed of 52 byte long records, so I slice them in a loop using :

var lContentObject = {};
for (var li=1; li<=lNumberOfRecords; li++) {
  var lBinaryData = lContentBytes.slice((li-1)*52, (li-1)*52+52);
  lContentObject[li] = {"binary_data": lBinaryData}; 
}

But the result is not what I expect. It is difficult for me to say if the server returns faulty data (unlikely) or if I do not process it properly on my side (likely). I should be able to turn the response into an array of unsigned 8 bit integers and decode them into a record of weather data that looks like this :

2015/01/01;00:30;-1,9;-1,9;-2,0;92;-3,1;1,6;W;0,80;4,8;W;-1,9;-2,1;-2,1;1031,5;0,00;0,0;0,422;0,000;18,7;42;5,5;17,4;8,14;1,2209;M;M;M;M;M;M;M;M;M;-0,6;-1,1;M;M;4;0;-0,6;-1,1;698;1;100,0;30

Instead, the data retrieved into lContentBytes shows negative numbers in the debugger, though it should not be the case. Although the total size of the byte array returned corresponds to what I expect (the number of records * 52), the last records 'sliced' out of the byte array are filled with '-1', which should not be the case.

I did a lot of research but didn't find any solution...

Here are the headers of the response to the GET request :

  • 'content-transfer-encoding':"binary",
  • Connection:"keep-alive",
  • 'Content-Encoding':"gzip",
  • Vary:"Accept-Encoding",
  • 'Content-Length':"161",
  • Date:"Wed, 15 Apr 2020 20:29:13 GMT",
  • 'Content-Type':"application/octet-stream"
6
  • Just in case it helps, I added the HTTP headers of the response.
    – ballatom
    Commented Apr 15, 2020 at 20:30
  • I have to apologize for my poor English skill. Unfortunately, I cannot understand about your issue. And I cannot understand about what I expect. In order to correctly understand about your question, can you provide a sample input and output values you expect?
    – Tanaike
    Commented Apr 15, 2020 at 23:40
  • Tanaike, I have edited the question to try and make it clearer. Here is also a link to the document that explains how the data has been encoded before being sent in the response of the GET request. Page 32 and 36 only.
    – ballatom
    Commented Apr 16, 2020 at 4:57
  • Thank you for replying. Your additional data is decoded data from the original data of lResponse. And lResponse retrieved from the URL is the binary data. You want to decode the data from lResponse. Is my understanding correct?
    – Tanaike
    Commented Apr 16, 2020 at 5:18
  • That is correct. And to decode the data from lResponse, I need to be able to see it as unsigned 8 bit integers. And I do not find the way to do this is Javascript (well Google Apps Script actually).
    – ballatom
    Commented Apr 16, 2020 at 6:08

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.