Go Down

Topic: Problem with GsmWebSerberExample (Read 1 time) previous topic - next topic

amadeus10

Jan 15, 2018, 06:44 pm Last Edit: Feb 12, 2018, 09:02 am by amadeus10
I have a problem when executing the GsmWebServer example of the MGRGSM library in my MKR gsm 1400.

Code: [Select]
#include <MKRGSM.h>

#include "arduino_secrets.h"
// Please enter your sensitive data in the Secret tab or arduino_secrets.h
// PIN Number
const char PINNUMBER[]     = "";
// APN data
const char GPRS_APN[]      = "myAPN.com";
const char GPRS_LOGIN[]    = "apn";
const char GPRS_PASSWORD[] = "apn";


// initialize the library instance
GPRS gprs;
GSM gsmAccess(true);     // include a 'true' parameter for debug enabled
GSMServer server(80); // port 80 (http default)

// timeout
const unsigned long __TIMEOUT__ = 10 * 1000;

void setup() {
  // initialize serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // connection state
  boolean connected = false;

  // Start GSM shield
  // If your SIM has PIN, pass it as a parameter of begin() in quotes
  while (!connected) {
    if ((gsmAccess.begin(PINNUMBER) == GSM_READY) &&
        (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) {
      connected = true;
    } else {
      Serial.println("Not connected");
      delay(1000);
    }
  }

  Serial.println("Connected to GPRS network");

  // start server
  server.begin();

  //Get IP.
  IPAddress LocalIP = gprs.getIPAddress();
  Serial.println("Server IP address=");
  Serial.println(LocalIP);
}

void loop() {


  // listen for incoming clients
  GSMClient client = server.available();



  if (client) {
    while (client.connected()) {
      if (client.available()) {
        Serial.println("Receiving request!");
        bool sendResponse = false;
        while (int c = client.read()) {
          if (c == -1) {
            break;
          } else if (c == '\n') {
            sendResponse = true;
          }
        }

        // if you've gotten to the end of the line (received a newline
        // character)
        if (sendResponse) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();
          client.println("<html>");
          // output the value of each analog input pin
          for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
            client.print("analog input ");
            client.print(analogChannel);
            client.print(" is ");
            client.print(analogRead(analogChannel));
            client.println("<br />");
          }
          client.println("</html>");
          //necessary delay
          delay(1000);
          client.stop();
        }
      }
    }
  }
}


The server is deployed correctly, and if I make a request from my terminal with wget it is answered. But only the first request. After closing the connection with the client, the serial monitor of my Arduino is showing the following message in loop, and it doesn't answer more requests:
AT+USORD=1,0
ERROR

Any idea? :smiley-confuse:
Thank you


sandeepmistry

Discussion was moved to Github: https://github.com/arduino-libraries/MKRGSM/issues/8

then addressed in the v1.1.1 MKRGSM release.

Go Up