0

Regarding Receive Byte in FONA
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Regarding Receive Byte in FONA

by yadnik17 on Sun Sep 01, 2019 2:23 pm

Hello sir,
I am using FONA module with Arduino to publish sensor data and at the same time, it subscribe to one feed to receive data. My code is working fine and there is no issue at all.
Only one problem I found that whenever any message coming on subscription feed it read all byte but not showing all bytes on the serial monitor.
In my code total, 63 bytes are read by my FONA module and it shows
"63 bytes available "
"63 bytes are read"

but when below code execute,
if (subscription == &ONOFFstatus)
{
Serial.print(F("Got: "));
Serial.println((char *)ONOFFstatus.lastread); // ONOFFstatus is my feed created on server to which i subscribed to recive data.
}

then it shows only 57 bytes on the serial monitor. other bytes are dropped. I don't know why it happens.

When I run the same code on Nodemcu it works perfectly for me. But as soon as I switch to FONA module it showing the same problem which is mentioned above. Please let me know where I am going wrong.
Your any help is appreciable.
Thank you.

yadnik17
 
Posts: 12
Joined: Sat Jun 08, 2019 10:46 am

Re: Regarding Receive Byte in FONA

by adafruit_support_mike on Thu Sep 05, 2019 4:24 am

Check your code to see if it's looking for newline ("\n") characters.

Functions like readBytesUntil() will only consume input characters until they find the character they're looking for.

adafruit_support_mike
 
Posts: 59131
Joined: Thu Feb 11, 2010 2:51 pm

Re: Regarding Receive Byte in FONA

by yadnik17 on Fri Sep 06, 2019 4:07 am

Hello sir,
Thanks for your reply.
As suggested by you I edited my code but not able to see any changes. It still shows the same problem as
'63 bytes available'
'63 bytes read'
but only 57 bytes are displayed on the serial monitor.

When executing the same code on NodeMCU there is no such problem occur it perfectly run and showing all bytes on the serial monitor.
Is it a module problem or something else?
Your any help is appreciable.
Thank you.

yadnik17
 
Posts: 12
Joined: Sat Jun 08, 2019 10:46 am

Re: Regarding Receive Byte in FONA

by adafruit_support_mike on Mon Sep 09, 2019 1:14 am

Post all of the code you have between the line that prints "63 bytes read" and the line that sends 57 bytes to the Serial monitor.

adafruit_support_mike
 
Posts: 59131
Joined: Thu Feb 11, 2010 2:51 pm

Re: Regarding Receive Byte in FONA

by yadnik17 on Thu Sep 19, 2019 10:41 am

Thanks for your reply.

Code: Select all | TOGGLE FULL SIZE
#include <Adafruit_SleepyDog.h>
#include <SoftwareSerial.h>
#include "Adafruit_FONA.h"
#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_FONA.h"

void setup()
{
  Serial.begin(9600);
  Serial.println(F("Adafruit FONA MQTT demo"));
}


void loop(){

// this is our 'wait for incoming subscription packets' busy subloop
  Adafruit_MQTT_Subscribe *subscription;
  while ((subscription = mqtt.readSubscription(5000)))
   {
      //----------------------------------------------------------------------------------------
      if (subscription == &ONOFFstatus)
      {
          Serial.print(F("Got: "));
          Serial.println((char *)ONOFFstatus.lastread);
      }
           
    } 
}       


On Serial monitor it prints,
63 bytes available
63 bytes read
but actually it prints 57 bytes.
I think this is because of the timeout problem.

Is timeout occur in fona module?
If yes then what is default value set in code? I searched for that but I haven't got.

Please give me suggestion about it.
Your any help is appreciable.
Thank you.
Last edited by adafruit_support_mike on Sat Sep 21, 2019 12:21 am, edited 1 time in total.
Reason: added CODE tags

yadnik17
 
Posts: 12
Joined: Sat Jun 08, 2019 10:46 am

Re: Regarding Receive Byte in FONA

by adafruit_support_mike on Sat Sep 21, 2019 12:48 am

By the time the FONA library prints "bytes read", that many bytes have already come from the FONA to the microcontroller.

Use this to print the reply data and post the results:

Code: Select all | TOGGLE FULL SIZE
char* ptr = (char*)ONOFFstatus.lastread;

for ( int i=0 ; ptr[ i ] && ( i < 70 ) ; i++ ) {
    char c = ptr[ i ];
    Serial.print( i );
    Serial.print(" = ");
    Serial.println( c );
}

adafruit_support_mike
 
Posts: 59131
Joined: Thu Feb 11, 2010 2:51 pm

Please be positive and constructive with your questions and comments.


cron