๐ŸŽ„โ›„โ„๏ธ๐ŸŽ It's beginning to look a lot like ADABOX-mas! The next ADABOX from Adafruit ships soon! Get yours now, or give as a gift! ๐ŸŽ„โ›„โ„๏ธ๐ŸŽ
0

Regarding Receive Byte in FONA
Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
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: 14
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: 59473
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: 14
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: 59473
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: 14
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: 59473
Joined: Thu Feb 11, 2010 2:51 pm

Re: Regarding Receive Byte in FONA

by yadnik17 on Sat Nov 02, 2019 1:51 pm

Hello sir,
I am using the FONA module to communicate with the server and its working fine. The only problem is when Simcard goes to another area because of roaming it's not connecting to the server. Is there any setting to use the same sim card to communicate with the server even in roaming.
The program stuck in one code. I'm sending a screenshot of my serial monitor.
Your any help is appreciable.
Thank you.
Attachments
Capture.PNG
Capture.PNG (110.1 KiB) Viewed 118 times

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

Re: Regarding Receive Byte in FONA

by adafruit_support_mike on Sun Nov 03, 2019 12:57 am

The return values from the AT+CREG? command are listed on page 91 of the SIM800 datasheet.

The '0' means the FONA has disabled messages that are generaed automatically when the connection status changes. The '5' indicates the FONA is registered to a roaming network.

Post the code you're using in that section between CODE tags and we'll see why it's looping.

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

Re: Regarding Receive Byte in FONA

by yadnik17 on Sun Nov 03, 2019 3:34 am

Thank you for your reply.

Actually, I'm using 'mqtt_fona ' example from your library where I'm sending my GPS location instead of photocell value to the server through the FONA module and I disabled watchdog timer for my project.
I know because of disabling watchdog timer it continuously looping a single command until it gets a valid response.

When my sim register to home network it works properly and I'm able to see the output on the server but as soon as my network registers to roam area it showing the above response as I explain in the previous post.

Is there any configuration in the library to connect to the server even when register to the roaming network?
Your any help is appreciable.
Thank you.

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

Re: Regarding Receive Byte in FONA

by adafruit_support_mike on Tue Nov 05, 2019 1:47 am

You'll need to change this part of the 'fonahelper.cpp' file (lines 25 to 27):

Code: Select all | TOGGLE FULL SIZE
  while (fona.getNetworkStatus() != 1) {
   delay(500);
  }
.getNetworkStatus() returns the CREG value, which will be 1 for the home network and 5 for roaming.

It would probably be easier to move the test off to a separate function like so:

Code: Select all | TOGGLE FULL SIZE
  while ( checkConnected() ) {
   delay(500);
  }

boolean checkConnected () {
    uint8_t code = fona.getNetworkStatus();

    if ( ( 1 == code ) || ( 5 == code ) ) {
        return( false )
    } else {
        return( true );
    }
}

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

Please be positive and constructive with your questions and comments.