Black Lives Matter - Action and Equality. ... Adafruit is open and shipping.
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: 17
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: 61124
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: 17
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: 61124
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: 17
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: 61124
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 284 times

yadnik17
 
Posts: 17
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: 61124
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: 17
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: 61124
Joined: Thu Feb 11, 2010 2:51 pm

Re: Regarding Receive Byte in FONA

by yadnik17 on Mon Dec 09, 2019 4:14 am

Thank you, sir.
The above code suggested by you is working perfectly for me. Once again Thank you.

I have one question regarding receive data in the FONA module. Whenever I send data from a server, FONA takes some time, in my case, it takes an average of 6 or 7 seconds to receive data.

Is FONA continuously polling to receive data from the server?

In mqtt_fona example, I observed that subscription code is executing and it checks data available or not.
Is there any interrupt base communication with FONA? This means as soon as data coming from a server the FONA should generate an interrupt and Arduino will collect that data.

Your any help is appreciable.
Thank you.

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

Re: Regarding Receive Byte in FONA

by yadnik17 on Mon Dec 09, 2019 2:17 pm

Hello sir,
In my project, I am sending GPS coordinate to the server and its working perfectly. In this project, I m sending coordinate by an external GPS module. After reading the documentation I come to know that sim808 is able to give GPS coordinates.

I want to replace that GPS module and want to keep sim808 as a standalone module to parse GPS coordinates and later then want to send that coordinate to the server. For that, what code I should change in the mqtt_fona example which is in your library. I need only latitude and longitude values. Which function I should call to get latitude and longitude values?

Your help is appreciable.
Thank you.

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

Re: Regarding Receive Byte in FONA

by yadnik17 on Thu Jan 09, 2020 4:28 am

Hello Sir,
As posted in the previous post, I'm using 'mqtt_fona' example to send GPS coordinate to the server instead of photocell value. So in this, I disable watchdog timer because my project was working fine and still working fine when I moving in strong network areas. As soon as I moved to an area where connectivity issue, controller sending the command to fona until it gets a valid response and if it did not get a valid response it remains in that loop forever (we can say it just like while loop).

Then I come to know, the importance of the watchdog timer. I implement it as it is already in the mqtt_fona example. but after implementation, another problem arises, which reset the controller when the controller trying to establish MQTT connection. I'm sending a screenshot of that part of the code. In the screenshot you can see controller sending one garbage value to the server that's why server not accepting a connection, for the first time I thought it is a wiring problem, then I did hardwire connection but still showing the same problem.

After analyzing I understand that,
- when I disable watchdog timer controller sending MQTT packets with garbage values upto 3rd or 4th iteration and at 5th or 6th iteration controller sends proper packets without
any garbage value and that connection get accepted by the server.
- when I enable the watchdog timer, the controller send a request to the server with garbage values upto two iterations and the controller gets reset.

To remove that garbage value problem I did all related modifications like hard wire solder, I changed the Arduino board too but showing the same problem.
After reading some articles related to watchdog timer in Arduino the maximum reset time is 8 second and I cant use another reset time greater than 8 seconds. I guaranteed if I increase reset time of controller such a way that it should perform sending of MQTT request at least upto 7th or 8th iteration( safe side). because I observe that at 5th or 6th iteration fona get connected to the server. if still after 7th or 8th iteration, if fona did not connect then reset controller. I don't know how to do this and increase reset time. if you have any idea about this please let me know.

Capture3.PNG
Capture3.PNG (148.06 KiB) Viewed 73 times

Your help is appreciated.
Thank you.

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

Please be positive and constructive with your questions and comments.