adrien3d / IO_WSSFM10-Arduino

Arduino library for the WSSFM10 Sigfox Module
https://plugblocks.com
MIT License
6 stars 8 forks source link

Fixing New Line feed in Sigfox AT responses #11

Closed nimasaj closed 5 years ago

nimasaj commented 5 years ago

Sigfox messages by default are ended with a new line feed. This will make an issue if you want to organize your output in the way you want. E.g. if you want ID and PAC to be in the same line separated by a comma (to be in a format of CSV file, so that it could be exported as a list.). A benefit of this change could be having a list of ID/PAC in CSV format, so that you can do a bulk register on the backend.

I recorded a Sigfox response to getID() function with a logic analyzer and this is the result (some parts are covered due to privacy). https://pasteboard.co/I87o12ZM.png Here you can find ASCII table as well for all characters, including 0x0A: http://www.asciitable.com/ To solve this issue, a small change is needed that is suggested by this pull request.

// get data
String getData(){
  String data = "";
  char output;

  while (!Sigfox.available()){
     blink();
  }

  while(Sigfox.available()){
    output = Sigfox.read();
    if (output!=0x0A){
      data += output;
    }

    delay(10);
  }

  return data;  
}

A quick test with updated getData() could be this one (with old getData() you cannot print ID & PAC in one line in the following example):

//Get Sigfox ID & PAC
String getID_PAC(){
  Sigfox.print("AT$I=10\n");  
  String id = getData();
  delay(100);
  Sigfox.print("AT$I=11\n");
  String pac= getData();
  delay(100);
  if(DEBUG){
    Serial.println("ID,PAC: "+id+", "+pac);
  }

  //return id;
}
adrien3d commented 5 years ago

Hi @nimasaj, thanks for your suggestion, I've commited in https://github.com/adrien3d/IO_WSSFM10-Arduino/commit/631332d682eeec28f4e7142110bed8a9476fd08b

nimasaj commented 5 years ago

Curious to know why you rejected my pull request, then applied the same changes yourself? I can open a new pull request to implement more improvements to the code, if you are not rejecting again.

adrien3d commented 5 years ago

Hi @nimasaj, in this commit, it was just to restore a debug print, I was a bit stubborn. But I will be welcome to accept improvements with future pull requests.

nimasaj commented 5 years ago

Hi @adrien3d, the new change will also be an update for this debug print. This is a small but worthy update, that many people can get benefited from. Also, your header file (IO_WSSFM10.h) is missing in this repo.

adrien3d commented 5 years ago

Hi @nimasaj, I can see it properly, can't you? https://github.com/adrien3d/IO_WSSFM10-Arduino/blob/master/IO_WSSFM10.h

nimasaj commented 5 years ago

@adrien3d , Sorry the issue was from my side. Everything is fine.