Example sketches for the new Arduino IDE for ESP8266

Moderator: igrr

User avatar
By ozayturay
#14353 I am using a copy of WiFiClient example to get data from a web page but I have three problems:

* There are lots of unwanted serial data output even if I haven't programmed them to display (only the last three should be displayed):
.scandone
.add 0
aid 7
pm open phy_2,type:2 0 0
cnt

connected with GMRK, channel 6
dhcp client start...
.ip:192.168.2.53,mask:255.255.255.0,gw:192.168.2.1
.
WiFi Connected
IP address: 192.168.2.53


* The data sometimes comes (with extra data like 19 and 0 that is not sent by the webpage php) and sometimes there is no data (trying to pull data in 30 seconds delays) coming:
Connecting To turay.ddns.net
Requesting URL: /data.php
HTTP/1.1 200 OK
Date: Mon, 13 Apr 2015 10:37:03 GMT
Server: Apache/2.4.10 (Ubuntu)
Accept-Ranges: bytes
X-Powered-By: PHP/5.5.12-2ubuntu4.3
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html

19
Incoming Data From Server
0


Connection Closed


Connecting To turay.ddns.net
Requesting URL: /data.php

Connection Closed


Connecting To turay.ddns.net
Requesting URL: /data.php

Connection Closed


Connecting To turay.ddns.net
Requesting URL: /data.php
HTTP/1.1 200 OK
Date: Mon, 13 Apr 2015 10:39:39 GMT
Server: Apache/2.4.10 (Ubuntu)
Accept-Ranges: bytes
X-Powered-By: PHP/5.5.12-2ubuntu4.3
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html

19
Incoming Data From Server
0


Connection Closed


* After some time it's even get worse and can't even connect:
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1
Connecting To turay.ddns.net
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1
Connection Failed
Connecting To turay.ddns.net
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1
Connection Failed
Connecting To turay.ddns.net
LmacRxBlk:1
LmacRxBlk:1
LmacRxBlk:1


The modified code used:
Code: Select all#include <ESP8266WiFi.h>

const char* SSID = "GMRK";
const char* PASS = "PASS";

const char* HOST = "turay.ddns.net";
const char* URL = "/data.php";

void setup()
{
  Serial.begin(115200);
  delay(10);
  Serial.println("");
  Serial.println("");
  Serial.print("Connecting To ");
  Serial.println(SSID);
 
  WiFi.begin(SSID, PASS);
 
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
    Serial.print(".");
  }

  Serial.println("");
  Serial.println("WiFi Connected"); 

  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
}

void loop()
{
  Serial.print("Connecting To ");
  Serial.println(HOST);
 
  WiFiClient Client;
 
  if (!Client.connect(HOST, 80))
  {
    Serial.println("Connection Failed");
    return;
  }
 
  Serial.print("Requesting URL: ");
  Serial.println(URL);
 
  Client.print(String("GET ") + URL + " HTTP/1.1\r\n" + "Host: " + HOST + "\r\n" + "Connection: close\r\n\r\n");
  delay(10);
 
  while(Client.available())
  {
    String Line = Client.readStringUntil('\r');
    Serial.print(Line);
  }
 
  Serial.println();
  Serial.println("Connection Closed");
  Serial.println();
  Serial.println();

  delay(30000);
}


Anybody with the same problems or have a solution?
User avatar
By gerardwr
#14364 Hi, tried your code:

At boot the ESP sends some output to the serial port at an awkward baudrate, and the output is unreadable. Everybody is annoyed about this, but there's no way preventing it. Maybe for some reason, it is readable in your Serial Monitor, it look like debug output from setting up the Wifi connection. Here's how it looks in the Arduino Serial Monitor here:

Schermafbeelding 2015-04-13 om 16.11.49.png


As you can see the 19 and 0 appears at every connection, I experience similar results in other similar sketches. I guess it's some control code in the received HTTP packet, packaging the actual message (like "Incoming Data From Server");

I did not experience the connection failure you mention. I set the delay to 3 secs and the connection is successful every time. Maybe a temporary server hickup?

Not sure this helps !
You do not have the required permissions to view the files attached to this post.
User avatar
By igrr
#14374
Code: Select allLmacRxBlk:1

Means that TCP/IP receive buffers are full with data and can not receive any more. Perhaps you are not reading all the data that is received.
Are you creating a new instance of WiFiClient on every loop() iteration? In this case you need the version more recent than 0e1b8ef, which fixed an issue with RX buffers not being released.
User avatar
By ozayturay
#14435
igrr wrote:Are you creating a new instance of WiFiClient on every loop() iteration? In this case you need the version more recent than 0e1b8ef, which fixed an issue with RX buffers not being released.


It's going so fast, I can't catch it. :)

Even it is fixed, it's not a good idea to recreate the object in the loop section. The example WiFiClient should be fixed. ;)

Edit: Adding these lines closed the debug lines but 19 and 0 are still there:

Code: Select all#include <HardwareSerial.cpp>

setup()
{
  uart_set_debug(UART_NO);
  Serial.begin(115200);
  ...
}