can`t run wifi or gprs server

Moderators: lily.li, violet, salmanfarisvp

Post Reply
back_kevin
Pre-kindergarten
Pre-kindergarten
Posts: 14
Joined: Sat Dec 06, 2014 7:07 am

can`t run wifi or gprs server

Post by back_kevin » Sat Dec 06, 2014 7:17 am

hi i try to run the wifi server and or the gprs server
i compile the wifi server from the LinkIt-ONE-IDE/examples/Starter_Kit_for_LinkIt/Extend_Lesson/L10_Web_Temp_Advanced/L10_Web_Temp_Advanced.ino with me network name and password
after upload to the linkit one i run the serial monitor but i see nothing
same probleme with gprs server sketch
all the other sketchs works fine.

Code: Select all

/*
 * Web Server & temperature
 * 
 * Note: 
 * 1.change the WIFI_AP to your ssid of Wi-Fi
 * 2.change WIFI_PASSWORD to key of your Wi-Fi
 * 3.as well as the WIFI_AUTH
 * 
 * When the code is finish uploading, open the serial monitor 
 * as soon as possible, then you can find that: "Please open your browser, and input the following address:"
 * and there will be an address below, such 192.168.1.100, copy it to your browser, press Enter, 
 * then you can see the temperature.
 */
#include <LTask.h>
#include <LWiFi.h>
#include <LWiFiServer.h>
#include <LWiFiClient.h>

#define WIFI_AP "BACK_HOME_1"
#define WIFI_PASSWORD "password"
#define WIFI_AUTH LWIFI_WPA                 // choose from LWIFI_OPEN, LWIFI_WPA, or LWIFI_WEP according to your WiFi AP configuration


LWiFiServer server(80);


float tp[10];



float getTemperature()
{

    static float tmp = 0.01;
    tmp += 0.01;
    return (20+tmp);
}

void getNewTemperature()
{
    float tp_new = getTemperature();
    
    for(int i=9; i>=1; i--)
    {
        tp[i] = tp[i-1];
    }
    
    tp[0] = tp_new;
}

void setup()
{
    LTask.begin();
    LWiFi.begin();
    Serial.begin(9600);
    
    for(int i=0; i<10; i++)
    {
        tp[i] = getTemperature();
    }

    // keep retrying until connected to AP
    Serial.println("Connecting to AP");
    while (0 == LWiFi.connect(WIFI_AP, LWiFiLoginInfo(WIFI_AUTH, WIFI_PASSWORD)))
    {
        delay(1000);
    }

    printWifiStatus();

    Serial.println("Start Server");
    server.begin();
    Serial.println("Server Started");
}

int loopCount = 0;

void loop()
{
    // put your main code here, to run repeatedly:
    delay(500);
    loopCount++;
    LWiFiClient client = server.available();
        
    getNewTemperature();
    
    if (client)
    {
        Serial.println("new client");
        // an http request ends with a blank line
        boolean currentLineIsBlank = true;
        
        unsigned long timer_out = millis();
        
        while (client.connected())
        {
        
            if(millis()-timer_out > 5000)break;
            
            if (client.available())
            {
                // we basically ignores client request, but wait for HTTP request end
                int c = client.read();
                Serial.print((char)c);

                if (c == '\n' && currentLineIsBlank)
                {
                    Serial.println("send response");
                    // send a standard http response header
                    client.println("HTTP/1.1 200 OK");
                    client.println("Content-Type: text/html");
                    client.println("Connection: close");  // the connection will be closed after completion of the response
                    client.println("Refresh: 5");  // refresh the page automatically every 5 sec
                    client.println();
                    client.println("<!DOCTYPE HTML>");
                    client.println("<html>");
                    // output the value of each analog input pin
                    
                    
                    for(int i=0; i<10; i++)
                    {
                        client.println(tp[i]);
                        client.println("<br />");
                    }
                    client.println("<br />");
                    client.println("</html>");
                    client.println();
                    break;
                }
                if (c == '\n')
                {
                    // you're starting a new line
                    currentLineIsBlank = true;
                }
                else if (c != '\r')
                {
                    // you've gotten a character on the current line
                    currentLineIsBlank = false;
                }
            }
        }
        // give the web browser time to receive the data
        delay(500);

        // close the connection:
        Serial.println("close connection");
        client.stop();
        Serial.println("client disconnected");
    }
}

void printWifiStatus()
{
    // print the SSID of the network you're attached to:
    Serial.print("SSID: ");
    Serial.println(LWiFi.SSID());

    // print your WiFi shield's IP address:
    IPAddress ip = LWiFi.localIP();
    Serial.println("Please open your browser, and input the following address:");
    Serial.println(ip);

    Serial.print("\r\nsubnet mask: ");
    Serial.println(LWiFi.subnetMask());

    Serial.print("gateway IP: ");
    Serial.println(LWiFi.gatewayIP());

    // print the received signal strength:
    long rssi = LWiFi.RSSI();
    Serial.print("signal strength (RSSI):");
    Serial.print(rssi);
    Serial.println(" dBm");
}
what can i try now

User avatar
loovee
Elementary-3
Elementary-3
Posts: 352
Joined: Fri Nov 02, 2012 9:15 am

Re: can`t run wifi or gprs server

Post by loovee » Sun Dec 07, 2014 10:34 am

Hi, maybe the Serial run too faster, cause you miss some log, you can add the following line to Setup() after Serial.bein(115200);

while(!Serial.available()); // until something input
while(Serial.available())Serial.read(); // clear serial data

please have a try. thanks

back_kevin
Pre-kindergarten
Pre-kindergarten
Posts: 14
Joined: Sat Dec 06, 2014 7:07 am

Re: can`t run wifi or gprs server

Post by back_kevin » Sun Dec 07, 2014 11:11 pm

thx i try it

i need to send a command to recive the serial output

now i see this (attachments)
when i go into the browser (mozilla) i recieve a timeout

Code: Select all

/*
 * Web Server & temperature
 * 
 * Note: 
 * 1.change the WIFI_AP to your ssid of Wi-Fi
 * 2.change WIFI_PASSWORD to key of your Wi-Fi
 * 3.as well as the WIFI_AUTH
 * 
 * When the code is finish uploading, open the serial monitor 
 * as soon as possible, then you can find that: "Please open your browser, and input the following address:"
 * and there will be an address below, such 192.168.1.100, copy it to your browser, press Enter, 
 * then you can see the temperature.
 */
#include <LTask.h>
#include <LWiFi.h>
#include <LWiFiServer.h>
#include <LWiFiClient.h>

#define WIFI_AP "BACK_HOME_1"
#define WIFI_PASSWORD "556890556890"
#define WIFI_AUTH LWIFI_WPA                 // choose from LWIFI_OPEN, LWIFI_WPA, or LWIFI_WEP according to your WiFi AP configuration


LWiFiServer server(80);


float tp[10];



float getTemperature()
{

    static float tmp = 0.01;
    tmp += 0.01;
    return (20+tmp);
}

void getNewTemperature()
{
    float tp_new = getTemperature();
    
    for(int i=9; i>=1; i--)
    {
        tp[i] = tp[i-1];
    }
    
    tp[0] = tp_new;
}

void setup()
{
    LTask.begin();
    LWiFi.begin();
    Serial.begin(115200);
    while(!Serial.available()); // until something input
    while(Serial.available())Serial.read(); // clear serial data
  
    
    for(int i=0; i<10; i++)
    {
        tp[i] = getTemperature();
    }

    // keep retrying until connected to AP
    Serial.println("Connecting to AP");
    while (0 == LWiFi.connect(WIFI_AP, LWiFiLoginInfo(WIFI_AUTH, WIFI_PASSWORD)))
    {
        delay(1000);
    }

    printWifiStatus();

    Serial.println("Start Server");
    server.begin();
    Serial.println("Server Started");
}

int loopCount = 0;

void loop()
{
    // put your main code here, to run repeatedly:
    delay(500);
    loopCount++;
    LWiFiClient client = server.available();
        
    getNewTemperature();
    
    if (client)
    {
        Serial.println("new client");
        // an http request ends with a blank line
        boolean currentLineIsBlank = true;
        
        unsigned long timer_out = millis();
        
        while (client.connected())
        {
        
            if(millis()-timer_out > 5000)break;
            
            if (client.available())
            {
                // we basically ignores client request, but wait for HTTP request end
                int c = client.read();
                Serial.print((char)c);

                if (c == '\n' && currentLineIsBlank)
                {
                    Serial.println("send response");
                    // send a standard http response header
                    client.println("HTTP/1.1 200 OK");
                    client.println("Content-Type: text/html");
                    client.println("Connection: close");  // the connection will be closed after completion of the response
                    client.println("Refresh: 5");  // refresh the page automatically every 5 sec
                    client.println();
                    client.println("<!DOCTYPE HTML>");
                    client.println("<html>");
                    // output the value of each analog input pin
                    
                    
                    for(int i=0; i<10; i++)
                    {
                        client.println(tp[i]);
                        client.println("<br />");
                    }
                    client.println("<br />");
                    client.println("</html>");
                    client.println();
                    break;
                }
                if (c == '\n')
                {
                    // you're starting a new line
                    currentLineIsBlank = true;
                }
                else if (c != '\r')
                {
                    // you've gotten a character on the current line
                    currentLineIsBlank = false;
                }
            }
        }
        // give the web browser time to receive the data
        delay(500);

        // close the connection:
        Serial.println("close connection");
        client.stop();
        Serial.println("client disconnected");
    }
}

void printWifiStatus()
{
    // print the SSID of the network you're attached to:
    Serial.print("SSID: ");
    Serial.println(LWiFi.SSID());

    // print your WiFi shield's IP address:
    IPAddress ip = LWiFi.localIP();
    Serial.println("Please open your browser, and input the following address:");
    Serial.println(ip);

    Serial.print("\r\nsubnet mask: ");
    Serial.println(LWiFi.subnetMask());

    Serial.print("gateway IP: ");
    Serial.println(LWiFi.gatewayIP());

    // print the received signal strength:
    long rssi = LWiFi.RSSI();
    Serial.print("signal strength (RSSI):");
    Serial.print(rssi);
    Serial.println(" dBm");
}

back_kevin
Pre-kindergarten
Pre-kindergarten
Posts: 14
Joined: Sat Dec 06, 2014 7:07 am

Re: can`t run wifi or gprs server

Post by back_kevin » Mon Dec 08, 2014 6:00 am

ok now it works i don`t know why but it works

back_kevin
Pre-kindergarten
Pre-kindergarten
Posts: 14
Joined: Sat Dec 06, 2014 7:07 am

Re: can`t run wifi or gprs server

Post by back_kevin » Mon Dec 08, 2014 8:54 pm

ok the probleme was the cache in firefox

but how can i add a button to the html part to control a led

back_kevin
Pre-kindergarten
Pre-kindergarten
Posts: 14
Joined: Sat Dec 06, 2014 7:07 am

Re: can`t run wifi or gprs server

Post by back_kevin » Wed Dec 10, 2014 7:26 am

hi i try at the moment this code:

Code: Select all

#include <LTask.h>
#include <LWiFi.h>
#include <LWiFiServer.h>
#include <LWiFiClient.h>


#define WIFI_AP "BACK_HOME_1"
#define WIFI_PASSWORD "556890556890"
#define WIFI_AUTH LWIFI_WPA// choose from LWIFI_OPEN, LWIFI_WPA, or LWIFI_WEP according to your WiFi AP configuration

LWiFiServer server(80);

// pin the LED is connected to
int ledPin = 3;

String readString; //string
boolean OUT6ON = false; // status flag




void setup()
{
  
  // set the LED pin as an output
  pinMode(ledPin, OUTPUT);
  
  digitalWrite(ledPin, LOW);   // Output initialization 
   
  LTask.begin();
  LWiFi.begin();
  Serial.begin(115200);
  while(!Serial.available()); // until something input
  while(Serial.available())Serial.read(); // clear serial data
  
   // keep retrying until connected to AP
  Serial.println("Connecting to AP");
  while (0 == LWiFi.connect(WIFI_AP, LWiFiLoginInfo(WIFI_AUTH, WIFI_PASSWORD)))
  {
    delay(1000);
  }

  printWifiStatus();

  Serial.println("Start Server");
  server.begin();
  Serial.println("Server Started");
}





void loop()
{
  // put your main code here, to run repeatedly:
  delay(500);

  LWiFiClient client = server.available();
  if (client)
  {
    Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected())
    {
      if (client.available())
      {
        // we basically ignores client request, but wait for HTTP request end
        char c = client.read();
        Serial.print((char)c);

        if (c == '\n' && currentLineIsBlank)
        {
          
          
          
        //    Serial.print(readString);
            
            if(readString.indexOf("L1=1") > -1) {//lets check if LED1 OUT6 should be on
              //led has to be turned ON
              Serial.println("LED ON");
              digitalWrite(ledPin, HIGH); // set the OUT6 on
              OUT6ON = true;
              }
            if(readString.indexOf("L1=0") > -1) {
              Serial.println("LED OFF");
              //led has to be turned OFF
              digitalWrite(ledPin, LOW); // set the OUT6 OFF
              OUT6ON = false;
            }
          
          
          
          
          
          
          
          
          
          Serial.println("send response");
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();
          // Page initialization  (remove in case You will use AJAX) 
          // AJAX is about updating parts of a web page, without reloading the whole page.
          client.print(F("<html><head><title>ARDUINO WEB CONTROL</title>"));
          client.print(F("<meta http-equiv=\"refresh\" content=\"30; url=http://192.168.1.242 \" /></head><body>"));
          // IMPOTANT add main pabe link for multy user connection 
          client.println("<h1>ARDUINO web control</h1>");
          //address will look like  http://192.168.1.xxx/?L=1 when submited
          client.println("<br />");
          client.println("<hr  />");
          client.println("<br />");
          
          
   client.print(F("<table border=\"1\"><tr>"));  // table start 

//********************************************************************************************
client.print(F("<td valign=\"middle\" >"));

             if (OUT6ON) {
                  client.print(F("<a href=\"/?L1=0\">"));
                  client.print(F("<img alt=\"\" height=\"50\" width=\"50\" src=\"http://www.ercreazioni.com/ugge/led1On.PNG\"/>"));
                }
                else
                {
                  client.print(F("<a href=\"/?L1=1\">"));
                  client.print(F("<img alt=\"\" height=\"50\" width=\"50\" src=\"http://www.ercreazioni.com/ugge/led1Off.PNG\"/>"));
              }
client.print(F("</td>"));

client.print(F("<td valign=\"middle\" >"));
client.print(F("<form action=\"L1=1\" ><input type=\"submit\" value=\"LED 1 ON\"/></form></td>")); // first button 
client.print(F("<td valign=\"middle\" >"));
client.print(F("<form action=\"L1=0\" ><input type=\"submit\" value=\"LED 1 OFF\"/></form></td>"));// second button
client.print(F("<td valign=\"middle\" >"));

             if (OUT6ON) {
                  client.print(F("<a href=\"/?L1=0\">"));
                  client.print(F("<img alt=\"\" height=\"50\" width=\"50\" src=\"http://www.ercreazioni.com/ugge/on.jpg\"/>"));
                }
                else
                {
                  client.print(F("<a href=\"/?L1=1\">"));
                  client.print(F("<img alt=\"\" height=\"50\" width=\"50\" src=\"http://www.ercreazioni.com/ugge/off.jpg\"/>"));
              }
client.print(F("</td>"));
client.print(F("<td valign=\"middle\" >"));
             if (OUT6ON) {
                  client.print(F("<a href=\"/?L1=0\">"));
                  client.print(F("<img alt=\"\" height=\"50\" width=\"75\" src=\"http://www.ercreazioni.com/ugge/button2On.PNG\"/>"));
                }
                else
                {
                  client.print(F("<a href=\"/?L1=1\">"));
                  client.print(F("<img alt=\"\" height=\"50\" width=\"75\" src=\"http://www.ercreazioni.com/ugge/button2Off.PNG\"/>"));
              }
client.print(F("</td>"));


client.print(F("</tr>"));             
//********************************************************************************************
client.print(F("</table>"));

          
          client.println("</html>");
          client.println();
          break;
        }
        if (c == '\n')
        {
          // you're starting a new line
          currentLineIsBlank = true;
        }
        else if (c != '\r')
        {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(500);

    // close the connection:
    Serial.println("close connection");
    client.stop();
    Serial.println("client disconnected");
  }
}

void printWifiStatus()
{
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(LWiFi.SSID());

  // print your WiFi shield's IP address:
  IPAddress ip = LWiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  Serial.print("subnet mask: ");
  Serial.println(LWiFi.subnetMask());

  Serial.print("gateway IP: ");
  Serial.println(LWiFi.gatewayIP());

  // print the received signal strength:
  long rssi = LWiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}
the web server works now
the page show my bouttoms but no reaction if i press it

the probleme come from this line
my code stop here

Code: Select all

if(readString.indexOf("L1=1") > -1) {//lets check if LED1 OUT6 should be on
              //led has to be turned ON
              Serial.println("LED ON");
              digitalWrite(ledPin, HIGH); // set the OUT6 on
              OUT6ON = true;
              }
i hope you can help thx

User avatar
loovee
Elementary-3
Elementary-3
Posts: 352
Joined: Fri Nov 02, 2012 9:15 am

Re: can`t run wifi or gprs server

Post by loovee » Wed Dec 10, 2014 9:16 pm

Hi, I am sorry that I'm not very familiar with network programming :cry:

I will have a try later, but I don't know if I can make it!

Post Reply