Linkit一个GPRS SERVER

时间:2016-10-31 12:13:59

标签: arduino

我有一个链接,它与Arduino类似。 我想通过GSM卡创建一个服务器。 我可以获取服务器的IP地址但不连接

这是我的代码: / *  GPRS Web服务器

显示更新计数器的简单Web服务器

 created 8 Mar 2012
 by Tom Igoe
Modified 20 Aug 2014
 by MediaTek Inc.
 */
#include <LGPRS.h>
#include <LGPRSClient.h>
#include <LGPRSServer.h>
#define GPRS_APN     "mobile.vodafone.it "
#define API_HOSTNAME "your_hostname_here.api.shipiot.net"
#define AUTH_HEADER  "your_auth_header_here"
LGPRSServer server(80); // port 80 (http)
String richiesta = "";
String serve = "arduino.cc";
int port = 80; // HTTP

void setup()
{
  // setup Serial port
  Serial.begin(115200);

  // detect APN
  while(!LGPRS.attachGPRS(GPRS_APN, NULL, NULL))
  {
    delay(500);
  }

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

  // start server
  server.begin();
Serial.println("Server Started");



  //Get IP.
  for(int i = 0; i < 5; ++i)
  {
    IPAddress localIP = server.serverIP();
    Serial.println("Server IP address=");
    Serial.println(localIP);

    delay(1000);
  }

}

void loop() {
  delay(50);
  // checking incoming clients
  LGPRSClient client = server.available();


 client.connect("http://google.it", 80);
 Serial.println("AVVIO client");
 Serial.print(client);


  if (client)
  {
    Serial.println("new client");
    while (client.connected())
    {
      if (client.available())
      {

         char c = client.read();
        richiesta.concat(c);
        Serial.print(richiesta);


        Serial.println("Receiving request!");
        bool sendResponse = false;

        while (int i = client.read()) {
          if ((char)i == '\n')
          {
            sendResponse = true;
            break;
          }

          if(i!=-1)
            Serial.print((char)i);
        }

        // 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.print("<head><title> TITOLO </title> <link rel='shortcut icon' type='image/x-icon' href='http://arduino.cc/en/favicon.png'/> </head>");
          client.println("<body><a href='/Led=1'> Accendi Led </a> <br> <a href='/Led=0'> Spegni Led </a> </body>");
          }
          client.println("</html>");
          //necessary delay
          delay(1000);
          client.stop();
        }
      }
    }
  }else{
    Serial.print("ERRORE");
  }
}

这是串行回复

Connected to GPRS network
Server Started
Server IP address=
10.157.39.19
Server IP address=
10.157.39.19
Server IP address=
10.157.39.19
Server IP address=
10.157.39.19
Server IP address=
10.157.39.19
AVVIO client
0ERROREAVVIO client

0 个答案:

没有答案