Arduino fona without monitor serial port

Adafruit cellular platform - SMS and IoT over celluar

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
korgo
 
Posts: 6
Joined: Sun Jun 05, 2016 6:11 am

Arduino fona without monitor serial port

Post by korgo »

My code work fine with arduino uno + fona when monitor serial port is open in Arduino IDE.

Code: Select all

#include "Adafruit_FONA.h"   //biblioteka do modułu foan 808
#include <SoftwareSerial.h>

#define FONA_RX 2
#define FONA_TX 3 
#define FONA_RST 4

char replybuffer[255]; // dane do odczytu
int wskaznik_gprs = 0;
int wkaznik_wykonania = 0;

SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX);
SoftwareSerial *fonaSerial = &fonaSS;
Adafruit_FONA fona = Adafruit_FONA(FONA_RST);
uint8_t readline(char *buff, uint8_t maxbuff, uint16_t timeout = 0);
uint8_t type;

String d;
void setup() {

  
 
  
//  while (!Serial);

  Serial.begin(115200);
 

  fonaSerial->begin(4800);
  if (! fona.begin(*fonaSerial)) {
    
    while (1);
  }
  type = fona.type();
 
  switch (type) {
    case FONA800L:
      break;
    case FONA800H:
      break;
    case FONA808_V1:
     break;
    case FONA808_V2:
      break;
    case FONA3G_A:
    break;
    case FONA3G_E:
    break;
    default: 
   break;
  }
 
}

void loop() {
         
       if(wskaznik_gprs==0){
       if (!fona.enableGPRS(true)){  
          delay(4000);
        }
        else{
           wskaznik_gprs = 1;
          }
       }   
        else if(wkaznik_wykonania==0){
         
       delay(1000);
        char url[80]="mysite";
        char data[80]="mylogin";
              // Post data to website
        uint16_t statuscode;
        int16_t length;
       d = "";
  
        
        if (!fona.HTTP_POST_start(url, F("application/x-www-form-urlencoded"), (uint8_t *) data, strlen(data), &statuscode, (uint16_t *)&length)) {
         
           fona.HTTP_POST_end();
        }
        else{
         
        while (length > 0) {
          while (fona.available()) {
            char c = fona.read();
           d+=c;

            length--;
            if (! length) break;
          }
        }
       
       
        }
        fona.HTTP_POST_end();

        
       if(d.substring(90,91)=="1" &  d.substring(117,118)=="0" &  d.substring(147,148)=="1"){
        
        wkaznik_wykonania=1;
        
        }
          
       if(d.substring(90,91)=="0" &  d.substring(117,118)=="1" &  d.substring(147,148)=="1"){
        
        wkaznik_wykonania=1;
        
        }
          
          
        }
   else if(wkaznik_wykonania==1){
   delay(1000);
     char url[80]="mysite";
        char data[80]="mylogin";
              // Post data to website
        uint16_t statuscode;
        int16_t length;
     
        if (!fona.HTTP_POST_start(url, F("application/x-www-form-urlencoded"), (uint8_t *) data, strlen(data), &statuscode, (uint16_t *)&length)) {
            fona.HTTP_POST_end();
         
        }
        else{
        while (length > 0) {
          while (fona.available()) {
          char c = fona.read();

            length--;
            if (! length) break;
          }
        }
        
        fona.HTTP_POST_end();
          wkaznik_wykonania=0;
   }}
 

I wanna make it that when arduino is power via USB its work but i dont know what to change to work.

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Arduino fona without monitor serial port

Post by adafruit_support_mike »

What part of the code doesn't work when you disconnect the Serial Monitor?

User avatar
korgo
 
Posts: 6
Joined: Sun Jun 05, 2016 6:11 am

Re: Arduino fona without monitor serial port

Post by korgo »

Code: Select all

   if (!fona.HTTP_POST_start(url, F("application/x-www-form-urlencoded"), (uint8_t *) data, strlen(data), &statuscode, (uint16_t *)&length)) {
         
           fona.HTTP_POST_end();
        }
        else{
         
        while (length > 0) {
          while (fona.available()) {
            char c = fona.read();
           d+=c;

            length--;
            if (! length) break;
          }
        }

With serial port code every time run instruction "else" but without every time run "IF".

I think something must be change in Adafruit_FONA.cpp to make "fona.HTTP_POST_start" work without monitor serial port.

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Arduino fona without monitor serial port

Post by adafruit_support_mike »

The FONA library uses the Serial port to print debug information, but you can shut that off.

Open the file Adafruit_FONA/includes/FONAConfig.h and comment out this line:

Code: Select all

#define ADAFRUIT_FONA_DEBUG
If that macro isn't defined, the library won't print any debug information. That should remove any connection to the Serial port.

Locked
Please be positive and constructive with your questions and comments.

Return to “FONA”