Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By martinayotte
#38243 Yes ! WifiClient is derived from Client, and Client is derived from Stream, and Stream is derived from Print.

In the mean time that your ESPs arrive, you can start writing the server python code, it can easily be manually tested with simple telnet tool.
User avatar
By Arduolli
#38301
martinayotte wrote:Yes ! WifiClient is derived from Client, and Client is derived from Stream, and Stream is derived from Print.
In the mean time that your ESPs arrive, you can start writing the server python code, it can easily be manually tested with simple telnet tool.


Hi martinayotte;
thanks for your help again!
As suggested, I followed the example in https://docs.python.org/2/library/socketserver.html , section "20.17.4.1. SocketServer.TCPServer Example" I used both the server and the client in the example. I added lines to store the received data in a file and - it works!

Very nice :D
I still have to think more about the implementation details (since the server runs off an USB stick, I would like to avoid saving the data file every couple of seconds, as I assume this will destroy the stick pretty quickly....)
But, the thing works basically.
Now I just hope that the ESP's come soon and that that side works as easily....
I'll keep you posted.
All the best.
User avatar
By Arduolli
#41745
martinayotte wrote:Yes ! WifiClient is derived from Client, and Client is derived from Stream, and Stream is derived from Print.
In the mean time that your ESPs arrive, you can start writing the server python code, it can easily be manually tested with simple telnet tool.


Hi martinayotte;
thanks again for your help!
Meanwhile, my ESP-01s arrived and I got it working - in principle.... but here is where I am stuck right now:
In my ESP/Arduino code, I gather data in packets of an array of 10 values. These 10 values I want to send from the ESP (as client) to a TCP server (via python, as you suggested earlier)
This is the code snippet on the ESP side:
Code: Select all  // This will send the data to the server
 for(int x = 0;x < loopmaxcount; x++) {  // send batch of timestamps server
    client.print(timestamp[x]);
  //    client.println();
 }


The problem: On the server side, I only get one entry (the last one).
Here is the python server snippet:
Code: Select all def handle(self):
        # self.request is the TCP socket connected to the client
        self.data = self.request.recv(1024)
        print "{} wrote:".format(self.client_address[0])
        print self.data
        file = open("newfile.txt", "a")
        file.write(self.data)
        file.close()
        # just send back an ok
        self.request.sendall('ok')


Both in the generated file newfile.txt as well as the on screen output, only the last of the 10 values per packet is shown.

What am I doing wrong?
I think, the problem lies on the ESP code side, as when I try with a mini python client to send 2 strings to the python server, this works and both are received and listed....

Can you - or anyone else give me some hints?
User avatar
By martinayotte
#41747 Unfortunately, we need to see more of your ESP code.
But I think the issue is that you are leaving the client opened, it should be close it and reconnect new client for each transmission.
Also, BTW, I see that you are sending all the 10 timestamps on the same line, you should at least add a separator such a comma or space between each.