Merci de partager votre travail dans "Réalisation et Projets finis" quand il sera terminé
D'accord pas de problème, si j'arrive à faire un truc fonctionnel, je partagerai tout, avec des photos du robot tout tout !!
Si non supercc j'ai quelques question !!!
J'ai trouvé ce petit script en python
#!/usr/bin/env python
import socket
TCP_IP = '192.168.0.50'
TCP_PORT = 65432
BUFFER_SIZE = 20 # Normally 1024, but we want fast response
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((TCP_IP, TCP_PORT))
s.listen(1)
conn, addr = s.accept()
print 'Connection address:', addr
while 1:
data = conn.recv(BUFFER_SIZE)
if not data: break
print "received data:", data
conn.send(data) # echo
conn.close()
et pour le script arduino :
/* Connects to the home WiFi network
* Asks some network parameters
* Sends and receives message from the server in every 2 seconds
* Communicates: wifi_server_01.ino
*/
#include <SPI.h>
#include <ESP8266WiFi.h>
char ssid[] = "SFR-6c00"; // SSID of your home WiFi
char pass[] = "Charly0406!"; // password of your home WiFi
IPAddress server(192,168,0,50); // the fix IP address of the server
WiFiClient client;
void setup() {
Serial.begin(115200); // only for debug
WiFi.begin(ssid, pass); // connects to the WiFi router
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
if (WiFi.status() == WL_CONNECTED)
{
Serial.println("0:1"); // 0 == wifi
}
if (!client.connect(server, 65432)) {
Serial.println("1:0");
delay(5000);
return;
}
else
{
Serial.println("1:1"); // 1 = serveur TCP
}
// Connection to the server
/* Serial.println("Connected to wifi");
Serial.print("Status: "); Serial.println(WiFi.status()); // Network parameters
Serial.print("IP: "); Serial.println(WiFi.localIP());
Serial.print("Subnet: "); Serial.println(WiFi.subnetMask());
Serial.print("Gateway: "); Serial.println(WiFi.gatewayIP());
Serial.print("SSID: "); Serial.println(WiFi.SSID());
Serial.print("Signal: "); Serial.println(WiFi.RSSI());*/
}
void loop () {
while (client.available() != 0) {
char c = client.read();
Serial.print(c);
}
while (Serial.available() != 0)
{
char c = Serial.read();
client.print(c);
}
// do something...
client.flush();
delay(1000); // client will trigger the communication after two seconds
}
sa fonctionne, j'envoi un message via le moniteur série par exemple :
- 123
et côté python je reçois ceci :
received data: 1
received data: 23
j'envoi bien la chaîne "123" sur la même ligne, je ne comprend pas d'où ça peut venir...
je ne comprends pas du tout pourquoi
EDIT : je pense avoir compris, en gros la boucle while se termine car il n'y a plus de donnée disponible sur le Serial, sauf que tout n'est pas arrivé, en gros la boucle tourne trop vite. Donc je vais plutôt déclencher l'envoi au serveur TCP lorsque j'ai mis un caractère de terminaison, comme ";"