These are chat archives for esp8266/Arduino

2nd
Apr 2017
Michael Miller
@Makuna
Apr 02 2017 06:21
@sri1609 When you configure your AP, what channel do you initialize it to? Are there other WiFi networks on the same or adjacent channels? Interference can cause large packet losses. Did you check the signal strength on the Station that connects to your AP? What strength levels are you seeing? TCP is a guaranteed, so if you are seeing losses you have a problem. Normally, minor things means "delays" not losses. 20 seconds before a timeout and thus considered a loss. So if you not seeing errors when you send and you are not seeing delays; then I suspect its something else in your sketch causing something.
@sri1609 Here is a library that I abstracted out a simple TCP setup JUST like you are talking about. The strange thing I ran into was that if I paused for longer than two seconds, the connection would just go dead. So I added a heartbeat that sends every two seconds to keep the connection alive. This should not be needed but it seems to be some limitation of their implementation.
sri1609
@sri1609
Apr 02 2017 08:00
@Makuna Thank you for your insight. Yes i checked the channel, if i set it to channel to 14 where no other networks are available, communication takes place but it is not detected by any other devices. I set it currently to channel 1, the results are better. Signal strength is close to -35 dBm and 90% of the time it is successful. But still some data randomly getting lost. Since i am planning to transfer 12-bit data from microcontroller, i need to send it as 2 byte pairs, so i cannot afford to lose any data in between. Am i missing something ?. I did read some other articles also. i changed the flashsize to 1Mb, and also included setNoDelay function in my program. These two steps improved the situation. But since i am new to this , i am not sure whether these two had any effect on this. Kindly guide me through this. Is there a practical limitation between consecutive data transfers? currently i have got no delays in my program between transfers. I would like to transfer 1 byte at a time .
Michael Miller
@Makuna
Apr 02 2017 08:10
@sri1609 Take a look at my library. There are also two projects that use; PandoraChest (AP) and PandoraBook (station). It sends two bytes also. Without a minimum sketch (least amount of complexity but still demonstrates the problem) its hard for anyone to help you.
Clemens Kirchgatterer
@everslick
Apr 02 2017 08:44
@sri1609 I send many KB of data per second over STA and also over AP mode. So it is definitely possible.
sri1609
@sri1609
Apr 02 2017 09:10
@everslick Thank you for your reply. I am wondering about any lower limit for these values. I read also about buffer size of around 1700 bytes for TCP stack. Is it true ?. What can go wrong in the program if i am receiving 90% of the time the correct data. Is there a way to access acknowledge message after successful transfer ?
Clemens Kirchgatterer
@everslick
Apr 02 2017 09:15
the only thing that comes to mind is, that using AP mode and STA mode at the same time (ON THE SAME ESP) can be tricky due to the fact, that the ESP only has ONE radio. so AP and STA share the same channel. if a client connects to the AP on the ESP this event determines the channel for both. if the ESP is connected to another ESP or AP it will lose that connection.
i work around this limitation by disabling STA mode as soon as a client connects to the AP of the ESP.
this does not apply to you, if you only use either AP oder STA mode, though.
sri1609
@sri1609
Apr 02 2017 09:18
@everslick Thank you for your reply. I have two ESP devices one set as AP (not as STATIONAP) and the other as STA. The STA can only connect to the ESP AP.
51<\r><\n>
54<\r><\n>
61<\r><\n>
64<\r><\n>
70<\r><\n>
73<\r><\n>
76<\r><\n>
78<\r><\n>
81<\r><\n>
82<\r><\n>
87<\r><\n>
89<\r><\n>
91<\r><\n>
94<\r><\n>
95<\r>
I just ran a for loop in client to transfer the iteration count as data to the master and this is what i was explaining earlier that i am losing data in between.
Clemens Kirchgatterer
@everslick
Apr 02 2017 09:31
void loop() {
client = server.available();
this looks very strange
sri1609
@sri1609
Apr 02 2017 09:33
I am checking is there a client available with data.
Clemens Kirchgatterer
@everslick
Apr 02 2017 09:34
yes, but you overwrite client with whatever server.available() returns on each loop iteration.
you only want to set client once as soon as it connects
look at server.hasClient()
Oliver Grüttner
@Defkil
Apr 02 2017 09:36
hey, somebody know if there are problems with the nodemcu v3 and usb3? i can't connect to the board. I can flash it without problems, but windows only see the controller if i push reset (can't connect anyway)
sri1609
@sri1609
Apr 02 2017 09:37
@everslick I will check it up. I am trying to find whether the client is still connected to the server in every iteration.
sri1609
@sri1609
Apr 02 2017 09:45
Also is it possible to send data from server to client ?. In that case which command do i use ? or in general whether a station can listen to a IP address and port ?
Michael Miller
@Makuna
Apr 02 2017 17:43
eh, client.write()?
sri1609
@sri1609
Apr 02 2017 20:42
@Makuna Yeah i know this command. but need to give server IP address as parameter. Do you think the problem i posted can be due to firmware issues . Which firmware do you recommend for using in arduino IDE . I mean i purchased the chip, flashed it with nodemcu and would like to use arduino IDE again. In that case it would be helpful
Martin Ayotte
@martinayotte
Apr 02 2017 20:52
@sri1609 , client.write() doesn't have IPAddr parameter, but simply char*/size.
What do you mean by firmware ? ArduinoIDE is the firmware !
Simply flash you new flash chip with ArduinoIDE, as simple as this ... ;-)
sri1609
@sri1609
Apr 02 2017 20:55
@martinayotte thank you for your comments. i have nodemcu running inside the chip. in that case can i simply use it with arduino IDE ?
Martin Ayotte
@martinayotte
Apr 02 2017 20:56
You mean NodeMCU Lua firmware ? it will be erase as soon as you upload Arduino sketch
sri1609
@sri1609
Apr 02 2017 20:56
@martinayotte yes exactly. okay thanks for your comment. Can you guide with the issue #3102 ?
Martin Ayotte
@martinayotte
Apr 02 2017 21:02
I've look at the code, and it seems that you are handling the communications one character at a time, on both server and client side. You should accumulate those character into a growing buffer and when reaching a newline, then you should do the processing of sending it to the other side.
Also, the server line of code "if(client.available())" should be replaced by "while(client.available() > 0)", and the "delay(1)" is a bit useless.
sri1609
@sri1609
Apr 02 2017 21:05
today i tried with for loop from client side to send the iteration count as data to the server
for eg. from 1 to 255 and again back to 0.
but server did not receive all the data .
Martin Ayotte
@martinayotte
Apr 02 2017 21:06
Also, I see in the client that you do your client.connect() in loop(), this is a problem if you wish to stay connected, it should be moved into setup()
That maybe the reason while your data is lost, because WiFiClient get destroyed when reaching the end of loop(), WiFiClient needs to be global.
sri1609
@sri1609
Apr 02 2017 21:14
@martinayotte thank you for your guidance. I have moved the WiFiClient to the global, client.connect to the setup section. i will check and update . regarding your suggestion about the packet size, that i need to accumulate characters into a buffer. I would like to send one byte at a time (which i receive from serial port of microcontroller) . Instead are you suggesting to store the incoming serial data into a buffer and send the buffer to the server ? i saw with client.write() i could send only bytes
Martin Ayotte
@martinayotte
Apr 02 2017 21:19
What type of data it is sending, plain text or binary ? Is it a Serial bridge with another MCU/Devices ?
client.write() is affectively sending bytes, but it can manage more than one at a time, it could be an array of bytes.
sri1609
@sri1609
Apr 02 2017 21:22
@martinayotte I have AVR microcontroller. It sends an 8-bit unsigned integer data to the client every 10 ms. This data has to be sent to the server by the client as it receives
Martin Ayotte
@martinayotte
Apr 02 2017 21:23
Ok, then buffer is maybe useless, but it will produce performance penalty. Did the move of connect() into setup fixed your original issue ?
BTW, why do you really needs bytes send every 10ms ? What are you doing with them after been received by server ?
I'm asking all that, because it is worth knowing what can be done. For example, you read sensors every 10ms, but you simply push the data into a database for doing graphics. Then, it is better to acculate them during 1 second, and send the whole array, it is more efficient.
sri1609
@sri1609
Apr 02 2017 21:31
@martinayotte you are correct. I am acquiring data from sensor through ADC in the microcontroller, get it sent to the client which is inside the machine and to the server through TCP,. The master is connected to PC, where i have a python script to read the data serially, and store it in sqlite database while plotting.
i have compiled but flashed the chip yet. I will get back to you on that . i have not thought about sending it as arrays yet .
Martin Ayotte
@martinayotte
Apr 02 2017 21:32
So, on the server side, there is no requirement that force to get them exactly at every 10ms, such as controlling a servo. This means the TCP communication will be much more efficient with buffers
sri1609
@sri1609
Apr 02 2017 21:36
@martinayotte in a way yes and no. I mean currently i am testing with the data of one of the ADC channels of microcontroller. But i may have to add additional sensors and use other channels as well . So in that case, to trace the channel from where the data is coming, i prefered to use one byte at a time or maximum 2 byte with a keyword for the channel. Because of these reasons i did not think about arrays. I will try that out also
Martin Ayotte
@martinayotte
Apr 02 2017 21:46
There is plenties of ways to transmit different data without having them mixed together. you can still accumulate those data, and format some packets to be send to server, the server will reformat it in its proper format into sqlite. Even plain text such as JSON string could be useful, JSON support arrays and key/val hashes.
sri1609
@sri1609
Apr 02 2017 21:57
@martinayotte Thank you for the insights. I would try out the ways you suggested and come back on that