Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.

JohanV's Content

There have been 6 items by JohanV (Search limited from 29-March 23)


By content type

See this member's

Sort by                Order  

#62795 SerialPort ESP 8266 ESP8266 Wifi

Posted by JohanV on 22 May 2015 - 02:57 PM in Netduino 2 (and Netduino 1)

After some testing i reccomend for serial data processing, 

some short code that quickly handles the datarecieved interrupt.

 

and about a 100 or 150 msec handling the data, but this is al depending on your project off-course.

 

       private int recBufferLength = 0;
       private byte[] recBuffer = new byte[2048];
 
            /* Data reception interrupt handler */
       internal void DataReceived_Interrupt(object com, SerialDataReceivedEventArgs arg)
       {
             // byte[] buffer = new byte[serialPort.BytesToRead];
             Int32 curRead = serialPort.Read(recBuffer, recBufferLength , serialPort.BytesToRead);
             recBufferLength += curRead;
        }

 

// i use some sort of data process moment, each 100 or 150 msec.

// at this moment i turn the data into a string.

 

 sRecieveData += new String(System.Text.Encoding.UTF8.GetChars(recBuffer, 0, recBufferLength));
 recBuffer = new byte[2048];
 
 
Also if there is an incomplete http response from the ESP8266, remember how the request was made.
Http1.0 or HTTP1.1.
testing against a linux apache server the HTTP1.1 could use Chunked responses.
( there will be some strange identifier ?? 8d4 in this case.) http://en.wikipedia....ansfer_encoding
 
+IPD,1059:
1412
HTTP/1.1 200 OK
Date: Fri, 22 May 2015 14:54:29 GMT
Server: Apache/2.2.29 (Unix)
X-Powered-By: PHP/5.4.40
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html; charset=ISO-8859-1
 
8d4
 
 
 
for a different request i get a response of 39342 bytes.
But still my response with the ESP8266 is choped at around 1450 bytes.
 
Host: www.netduino.com
Connection: close
Accept: text/html
User-Agent: ESP8266
 
 
 
 
+IPD,1412:HTTP/1.1 200 OK
Content-Length: 39342
Content-Type: text/html
Last-Modified: Sun, 10 May 2015 19:52:13 GMT
Accept-Ranges: bytes
ETag: "2d348ccf5a8bd01:0"
Server: Microsoft-IIS/8.0
X-Powered-By: ASP.NET
Set-Cookie: ARRAffinity=0fc3cc817ad58a64bbaff8bc51eb48d3224777aeb37b322d17e1369cad947f99;Path=/;Domain=www.netduino.com
Date: Fri, 22 May 2015 14:51:24 GMT
Connection: close
 
?<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR...nsitional.dtd">
 
<head>
<meta content="en-us" http-equiv="Content-Language" />
<meta content="text/html; charset=utf-8" http-e



#62788 SerialPort ESP 8266 ESP8266 Wifi

Posted by JohanV on 22 May 2015 - 07:26 AM in Netduino 2 (and Netduino 1)

Also after getting some serial port data back, and do some string searching.

I did not check how long this takes. an array search will probably be a lot faster ?

 

                this.SendTimeOut = System.DateTime.Now;

                // search string
                for (int i1 = 0; i1 < 10000; ++i1)
                {
                    test.IndexOf(":" + i1.ToString());
                }
                Debug.Print(this.SendTimeOut +"::"+ System.DateTime.Now);



#62787 SerialPort ESP 8266 ESP8266 Wifi

Posted by JohanV on 22 May 2015 - 07:13 AM in Netduino 2 (and Netduino 1)

Hi Chris,

 

Thanks for the support, 

I did some string tests.

 

                this.SendTimeOut = System.DateTime.Now;
                System.String test = "";
                for (int i1 = 0; i1 < 10000; ++i1)
                {
                    test += ":" + i1.ToString();
                }
                Debug.Print(this.SendTimeOut +"::"+ System.DateTime.Now);
 
this itteration takes about 68 seconds for 10000 repeats.
And turns out it does only 147 times per second the ( += string function ).
so this is only 1200 bytes per second, not fast enough for the 9600 baud rate.
 
I will look into some array functions to do similar functionality.
 
I know the STM32F427 is quite fast with array functions.
 
 
Any one have some nice example that will run fast ?



#62773 SerialPort ESP 8266 ESP8266 Wifi

Posted by JohanV on 21 May 2015 - 08:41 AM in Netduino 2 (and Netduino 1)

Hi Chris,

 

Actualy, i changed the speed to 115200, and get about 1450 bytes at each http response.

so quite an improvement. Different than i expected....

But some data is still choped, at the end, this is not a real problem, for only sending some simple sensor data to a webserver or database.

 

I get the "RXOver" type in ErrorReceived_Interrupt(object sender, SerialErrorReceivedEventArgs e)

This is an input buffer overflow ?

 

So to fix this i need to speed up reading and processing data from the input buffer ?

 

I'm still wondering what the slow part is of this code (DataReceived_Interrupt) ?

there is an example of the esp8266 driver ( https://github.com/brusdev/ATModem )

this code handles the return data of the module in arrays, i think to avoid slow string processing ?




#62750 SerialPort ESP 8266 ESP8266 Wifi

Posted by JohanV on 19 May 2015 - 11:26 PM in Netduino 2 (and Netduino 1)

This module has only 256 bytes cache. as far as i can test, and read on the internet.

 

also i did not think about that the data rate could be to slow, 

during testing i saw with the interrupt routine many times only get 2 to 4 characters.

but i will change it and see what happens.

 

i know the baud rate can be changed of this module. it started with 115200, and i thought it would be to fast for netmf.

 

so it's not the string manipulation that is slow but rather the interupt trigger fired many times ?

 

if i get serial data back bigger than about 256 bytes the stream is choped at irregular places

 

 

thanks

 

i will try it tomorrow.




#62728 SerialPort ESP 8266 ESP8266 Wifi

Posted by JohanV on 18 May 2015 - 12:47 PM in Netduino 2 (and Netduino 1)

Hello I'm trying to interface the ESP8266 WiFi with AT commands.

 

 

Also any one intresting in WiFi for the Netduino,

( better just buy the new Netduino 3 with out of the box Wifi !!! :D )

 

 

At the moment i'm using the module, with this firmware (0018000902-AI03).

At 9600 bit ps.

 

 

most functions are working now.

 

my problem is the ESP 8266 only have 256 byte buffer. so to read the 256 byte buffer ( 2048 bit. ).

after about 200 ms you start to loose data.

 

At the moment i spend quite some time to get me familiar to the .net micro framework serial port.

 

The serial port is read with an interupt.

This interupt is started in a new thread. so this is triggered after some data is recieved.

somtimes 2 bytes somtimes 10 or more.

 

serialPort.DataReceived += new SerialDataReceivedEventHandler(DataReceived_Interrupt);

serialPort.ErrorReceived += new SerialErrorReceivedEventHandler(ErrorReceived_Interrupt);

 

Also at first i did not have an Error Revieved interrupt, and was unable to find the problems i had with this module.

turns out it's an buffer input overflow. ( 256 bytes max ).

 

I changed the handling of the recieved data, and turns out, my approach is to slowy ( or the neduino ? ). For this module.

I'm using some string functions that i suspect are to slowly ?

 

static System.String sRecieveData = "";

static SerialPort serialPort;

 

//* Data reception interrupt handler */

internal void DataReceived_Interrupt(object com, SerialDataReceivedEventArgs arg)

{

  byte[] bytes = new byte[serialPort.BytesToRead];

  // read the bytes

  serialPort.Read(bytes, 0, bytes.Length);

  // convert the bytes into a string

  String strLine = new String(System.Text.Encoding.UTF8.GetChars(bytes, 0, bytes.Length));

  sRecieveData += strLine;

}

 

 

/* Data reception interrupt handler */

internal void DataReceived_Interrupt(object com, SerialDataReceivedEventArgs arg)

{

  byte[] buf = new byte[1];

  System.String sRecievePart = "";

  while (serialPort.BytesToRead > 0)

  {

    serialPort.Read(buf, 0, 1);

    sRecievePart += (char)buf[0];

  }

  sRecieveData += sRecievePart;

}

 

So my question is what is the best way to handle the recieved serial data ? so i not get the buffer overflow error. 

 

 

Thanks





home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.