Show Posts
|
|
Pages: [1] 2
|
|
1
|
International / Français / Re: UDP depuis serveur Free
|
on: April 13, 2012, 02:44:48 pm
|
Ok ok, merci à tous pour vos réponse, je vais réfléchire à une autre solution... Ca marchait si bien sur mon wamp (avec le module socket activé  ) Mon sketch, au départ, log des températures dans une base mysql pour mon chauffage. Vous l'aurez deviné je voulais pouvoir changer la consigne de température à distance. Juste une dernière question sur IPV6 IPV4, je charge a distance des pages sur mon serveur wamp ou dur l'arduino en mode server en appelant une ip public au format IPV4 et kes redirections de port sont faites sous la forme 192.168.0.XX, où est L'ip V6 dans tout ca?? (ma box est bien en IPV6) un éclaircissement peut etre? Merci encore
|
|
|
|
|
3
|
International / Français / Re: UDP depuis serveur Free
|
on: April 12, 2012, 04:40:41 pm
|
|
@Skywodd, je t ai fait un petit MP avec le lien de phpsecureinfo sur mon serveur free.
Ma box est en IPV6, ca pose un problème?
Si tu regarde mon code, j affiche deja le code erreur :unable to write to socket [101], ce qui donne Network is unreachable.
Oui le port UDP est bien routé.
@OSAKA J'ai également trouvé ces infos mais je ne suis pas sur qu elles soient encore d actu, en effet, voici ce que retourne un serveur mutualisé chez OVH sur lequel socket n'est pas autorisé : Operation not permitted
grrrrrrr
|
|
|
|
|
4
|
International / Français / Re: UDP depuis serveur Free
|
on: April 12, 2012, 04:03:35 pm
|
Merci pour ta reponse infobarquee. Sur le port 80 j ai une redirection vers mon PC avec le serveur Wamp ceci dit, je pourrais le cutter. Je n ai pas essayé de reboot la box, ce n'est a priori pas nécessaire mais je vais essayer aussi. j ai a peu près tout essayé donc je tente tout ce que je n ai pas deja fait  @+
|
|
|
|
|
5
|
International / Français / UDP depuis serveur Free
|
on: April 12, 2012, 03:43:08 pm
|
Bonjour à tous, J ai un petit bout de code qui fait un fader sur une diode via une commande ethernet UDP depuis un serceur php qui tourne en local sur mon pc. Le PC et la carte arduino avec le shield ethernet sont branchés sur une freebox revolution en mode router. Mon problème, ca fonctionne très bien dans cette config, meme depuis l'exterieur, mais j aimerais héberger tout ca sur un serveur Free pour ne pas laisser mon PC tourner. Voici l erreur que je rencontre : socket_sendto() [function.socket-sendto]: unable to write to socket [101] <?php //phpinfo(); //$valeur_led = $_POST["led1"]; // récupération de la valeur transmise en méthode POST $valeur_led ="59"; $host="88.167.XXX.XXX"; // Adresse ip défini dans le code arduino $port=8888; // Port défini dans le code arduino
$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); socket_sendto($socket, $valeur_led , strlen($valeur_led), 0, $host, $port); echo socket_last_error(); echo "<br>"; echo socket_strerror(socket_last_error()); socket_close($socket); ?>
le Ino: #include <SPI.h> // needed for Arduino versions later than 0018 #include <Ethernet.h> #include <EthernetUdp.h> // UDP library from: bjoern@cs.stanford.edu 12/30/2008 // Enter a MAC address and IP address for your controller below. // The IP address will be dependent on your local network: uint8_t hwaddr[6] = {0xDE, 0xAD, 0xBE, 0xEF, 0xBA, 0xBE}; // mac-adress of arduino //uint8_t ipaddr[4] = {192, 168, 0, 10}; // IP-adress of arduino uint8_t ipaddr[4] = {88,167,233,135}; // IP-adress of arduino uint8_t gwaddr[4] = {192, 168, 0, 254}; // IP-adress of gateway ( for later DNS implementation) uint8_t dns[4] = {192, 168, 0, 254}; // IP-adress of gateway ( for later DNS implementation) uint8_t subnet[4] = {255, 255, 255, 0}; // subnetmask ( for later DNS implementation) //uint8_t serverip[4] = {88,167,233,135}; // IP-adress of server arduino sends data to //uint8_t ipaddr[4] = {192, 168, 0, 10}; unsigned int localPort = 8888; // local port to listen on // the next two variables are set when a packet is received byte remoteIp[4]; // holds received packet's originating IP unsigned int remotePort; // holds received packet's originating port // buffers for receiving and sending data char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet, char ReplyBuffer[] = "acknowledged"; // a string to send back EthernetUDP Udp; void setup() { // start the Ethernet and UDP: Ethernet. begin(hwaddr,ipaddr,dns,gwaddr,subnet); // start up ethernet Udp.begin(localPort); Serial.begin(9600); } void loop() { // if there's data available, read a packet int packetSize = Udp.parsePacket(); if(packetSize) { Serial.print("Received packet of size "); Serial.println(packetSize); Serial.print("From "); IPAddress remote = Udp.remoteIP(); for (int i =0; i < 4; i++) { Serial.print(remote , DEC); if (i < 3) { Serial.print("."); } } Serial.print(", port "); Serial.println(Udp.remotePort()); memset(packetBuffer, 0, UDP_TX_PACKET_MAX_SIZE); // read the packet into packetBufffer and get the senders IP addr and port number Udp.read(packetBuffer,UDP_TX_PACKET_MAX_SIZE); Serial.println("Contents:"); Serial.println(packetBuffer); analogWrite(9, atoi(packetBuffer)); //utiliser la valeur reçu pour allumer la led } //delay(250); }
Ca fait 3 jours que je cherche dans mon code et sur le net, ma box est bien paramétrée pour rediriger les port (enfin je crois  ) Si quelqu un a une idée, Skywood si tu passes dans le coin... Merci à tous
|
|
|
|
|
11
|
Using Arduino / Networking, Protocols, and Devices / Re: Ethernet client and UDP together in same sketch
|
on: April 10, 2012, 12:55:44 pm
|
This is the script where udp doesn't work: ///////////////////////////// // mode client // // charge la page bdd.php // // avec la température en argument // // FONCTIONNEL // ///////////////////////////// #include <Ethernet.h> //library for ethernet functions #include <Client.h> //library for client functions #include <SPI.h> #include <EthernetUdp.h> // UDP library from: bjoern@cs.stanford.edu 12/30/2008 // Ethernet settings uint8_t hwaddr[6] = {0xDE, 0xAD, 0xBE, 0xEF, 0xBA, 0xBE}; // mac-adress of arduino uint8_t ipaddr[4] = {192, 168, 0, 10}; // IP-adress of arduino uint8_t gwaddr[4] = {192, 168, 0, 254}; // IP-adress of gateway ( for later DNS implementation) uint8_t subnet[4] = {255, 255, 255, 0}; // subnetmask ( for later DNS implementation) uint8_t serverip[4] = {88,167,233,135}; // IP-adress of server arduino sends data to uint8_t serverport = 80; // the port the arduino talks to //byte ip[] = {88,167,233,135}; // ip in lan byte ip[] = { 192, 168, 0, 10 }; // ip in lan //IPAddress server(88,167,233,135); unsigned int localPort = 8888; // local port to listen on // the next two variables are set when a packet is received byte remoteIp[4]; // holds received packet's originating IP unsigned int remotePort; // holds received packet's originating port // buffers for receiving and sending data char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet, char ReplyBuffer[] = "acknowledged"; // a string to send back EthernetUDP Udp; EthernetClient client; // make a new instance from type "Client" named "client", giving it // serverip and serverport bool connected = false; // yes-no variable (boolean) to store if the arduino is connected to the server int i = 0; // variable to count the sendings to the server //-------------------------- // heure //int refresh=0; int top=0; int last_top=0; int seconde=50; int seconde2=0; int minute=59; int heure=23; long last_time=0; int dizaine; //--------------------------- void setup(void) // setup-function runs at the startup of the arduino { pinMode(9, OUTPUT); digitalWrite(9, HIGH); Serial.begin(9600); // start the serial port Serial.println("demarrage..."); Ethernet. begin(hwaddr,ip,gwaddr,subnet); // start up ethernet digitalWrite(9, LOW); // start the Ethernet and UDP: // Ethernet.begin(mac,ip); Udp.begin(localPort); } void loop(void) // loop function runs over and over again { listen_udp(); if (seconde==59) { digitalWrite(9, HIGH); if(!connected) { // if "not" connected print: not connected  Serial.println("Not connected"); if (client.connect(serverip, 80)){ // if connected, set variable connected to "true" and connected = true; //delay(100); client.print("GET /arduino/bdd.php?temp=22"); Serial.print("GET /arduino/bdd.php?temp=22"); client.println(" HTTP/1.1"); Serial.println(" HTTP/1.1"); client.println("Host: www.google.fr"); Serial.println("Host: www.google.fr"); client.println("User-Agent: Arduino"); Serial.println("User-Agent: Arduino"); client.println("Accept: text/html"); Serial.println("Accept: text/html"); client.println("Connection: close"); Serial.println("Connection: close"); client.println(); Serial.println(); } else{ Serial.println("Cannot connect to Server"); // else block if the server connection fails (debugging) } } else { delay(200); // while (client.connected() && client.available()) { // when connected and availabe: char c = client.read(); // read the answer of the server and Serial.print(c); // print it to serial port } // Serial.println(); // client.stop(); // stop the connection and set connected = false; // "connected" to false } digitalWrite(9, LOW); //delay(1000); } horloge(); if(top==2){top=0; }//on remet le compteur des tops seconde à0 } int horloge() { if(millis()-last_time>=500) { last_time=millis(); top++; if(top==2){seconde+=1;}//incrementation des secondes toutes les 2x 500ms if(seconde>59)//incrementation des minutes {seconde=0; minute=minute++;} if(minute>59)//incrementation des heures {minute=0;heure=heure++;} if(heure>23) {heure=0;} //---------- affichage heures min sec et séparateurs //if(seconde%2==0){lcd.setCursor(8, 1); lcd.print(" ");}//si secondes sont paires, affiche separateur droit //else{lcd.setCursor(8, 1); lcd.print(":");} //sinon affiche le separateur gauche dizaine=((heure*60+minute)/10); //affiche_heure(); } return dizaine; return top; } void listen_udp() { int packetSize = Udp.parsePacket(); if(packetSize) { Serial.print("Received packet of size "); Serial.println(packetSize); Serial.print("From "); IPAddress remote = Udp.remoteIP(); for (int i =0; i < 4; i++) { Serial.print(remote , DEC); if (i < 3) { Serial.print("."); } } Serial.print(", port "); Serial.println(Udp.remotePort()); memset(packetBuffer, 0, UDP_TX_PACKET_MAX_SIZE); // read the packet into packetBufffer and get the senders IP addr and port number Udp.read(packetBuffer,UDP_TX_PACKET_MAX_SIZE); Serial.println("Contents:"); Serial.println(packetBuffer); analogWrite(9, atoi(packetBuffer)); //utiliser la valeur reçu pour allumer la led } }
Thank you again
|
|
|
|
|
12
|
Using Arduino / Networking, Protocols, and Devices / Ethernet client and UDP together in same sketch
|
on: April 10, 2012, 12:53:41 pm
|
Hello I'm trying to run Ethernet client to write data in a mysql server and read UDP to turn on/off functions on arduino. I have already wrote 2 sketchs one for ethernet and one for UDP, they are running properly but when I try to join them in the same sketch, Udp doesn't run... client sketch : ///////////////////////////// // mode client // // charge la page bdd.php // // avec la température en argument // // FONCTIONNEL // ///////////////////////////// #include <Ethernet.h> //library for ethernet functions #include <Client.h> //library for client functions #include <SPI.h> // Ethernet settings uint8_t hwaddr[6] = {0xDE, 0xAD, 0xBE, 0xEF, 0xBA, 0xBE}; // mac-adress of arduino //uint8_t ipaddr[4] = {192, 168, 0, 17}; // IP-adress of arduino //uint8_t gwaddr[4] = {192, 168, 0, 1}; // IP-adress of gateway ( for later DNS implementation) //uint8_t subnet[4] = {255, 255, 255, 0}; // subnetmask ( for later DNS implementation) uint8_t serverip[4] = {88,167,XXX,XXX}; // IP-adress of server arduino sends data to uint8_t serverport = 80; // the port the arduino talks to EthernetClient client; // make a new instance from type "Client" named "client", giving it // serverip and serverport int timeout=0; bool req_sended = 0; bool connected = false; // yes-no variable (boolean) to store if the arduino is connected to the server int i = 0; // variable to count the sendings to the server //-------------------------- // heure //int refresh=0; int top=0; int last_top=0; int seconde=50; int seconde2=0; int minute=59; int heure=23; long last_time=0; int dizaine; //--------------------------- long freq=0; void setup(void) // setup-function runs at the startup of the arduino { pinMode(9, OUTPUT); digitalWrite(9, HIGH); Serial.begin(9600); // start the serial port Serial.println("demarrage..."); Ethernet. begin(hwaddr); // start up ethernet digitalWrite(9, LOW); } void loop(void) // loop function runs over and over again { freq++; //if (((minute%5)==0&&seconde==0)&&req_sended==0) if ((seconde==0||seconde==30)&&req_sended==0) { //Serial.println(seconde); timeout=0; if(!connected) { // if "not" connected print: not connected  Serial.println(); Serial.println(" <----===========---->"); //Serial.println("Not connected"); digitalWrite(9, HIGH); if (client.connect(serverip, 80)){ // if connected, set variable connected to "true" and connected = true; //delay(100); client.print("GET /arduino/bdd.php?temp=22"); Serial.print("GET /arduino/bdd.php?temp=22"); client.println(" HTTP/1.1"); Serial.println(" HTTP/1.1"); client.println("Host: www.google.fr"); Serial.println("Host: www.google.fr"); client.println("User-Agent: Arduino"); Serial.println("User-Agent: Arduino"); client.println("Accept: text/html"); Serial.println("Accept: text/html"); client.println("Connection: close"); Serial.println("Connection: close"); client.println(); Serial.println(); req_sended=1; } else{ Serial.println("Cannot connect to Server"); // else block if the server connection fails (debugging) } } while (!client.available() && timeout<200) { timeout++; if(timeout==200){Serial.print("Time out !"); Serial.println(timeout);} delay(25); } Serial.print("Delay : ");Serial.println(timeout); digitalWrite(9, LOW); } //delay(500); // while (client.connected() && client.available()) { // when connected and availabe: char c = client.read(); // read the answer of the server and Serial.print(c); // print it to serial port } // //Serial.println(); // client.stop(); // stop the connection and set connected = false; // "connected" to false //delay(1000); horloge(); if(top==2){top=0; //on remet le compteur des tops seconde à 0 req_sended=0; //Serial.println();Serial.print("freq : ");Serial.println(freq); freq=0;} } int horloge() { if(millis()-last_time>=500) { last_time=millis(); top++; if(top==2){seconde+=1;}//incrementation des secondes toutes les 2x 500ms if(seconde>59)//incrementation des minutes {seconde=0; minute=minute++;} if(minute>59)//incrementation des heures {minute=0;heure=heure++;} if(heure>23) {heure=0;} //---------- affichage heures min sec et séparateurs //if(seconde%2==0){lcd.setCursor(8, 1); lcd.print(" ");}//si secondes sont paires, affiche separateur droit //else{lcd.setCursor(8, 1); lcd.print(":");} //sinon affiche le separateur gauche dizaine=((heure*60+minute)/10); //affiche_heure(); } return dizaine; return top; } UDP sketch : ////////////////////////////////// // FADER DIODE SUR PORT 9 // // EN UDP AVEC SCRIPT PHP AJAX // // IP: 192, 168, 0, 10 // // PORT 8888 // ////////////////////////////////// #include <SPI.h> // needed for Arduino versions later than 0018 #include <Ethernet.h> #include <EthernetUdp.h> // UDP library from: bjoern@cs.stanford.edu 12/30/2008 // Enter a MAC address and IP address for your controller below. // The IP address will be dependent on your local network: byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address byte ip[] = { 192, 168, 0, 10 }; // ip in lan //byte gateway[] = { 192, 168, 0, 1 }; // internet access via router //byte subnet[] = { 255, 255, 255, 0 }; //subnet mask //EthernetServer server = EthernetServer(80); //port 80 unsigned int localPort = 8888; // local port to listen on // the next two variables are set when a packet is received byte remoteIp[4]; // holds received packet's originating IP unsigned int remotePort; // holds received packet's originating port // buffers for receiving and sending data char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet, char ReplyBuffer[] = "acknowledged"; // a string to send back EthernetUDP Udp; void setup() { // start the Ethernet and UDP: Ethernet.begin(mac,ip); Udp.begin(localPort); Serial.begin(9600); } void loop() { // if there's data available, read a packet int packetSize = Udp.parsePacket(); if(packetSize) { Serial.print("Received packet of size "); Serial.println(packetSize); Serial.print("From "); IPAddress remote = Udp.remoteIP(); for (int i =0; i < 4; i++) { Serial.print(remote , DEC); if (i < 3) { Serial.print("."); } } Serial.print(", port "); Serial.println(Udp.remotePort()); memset(packetBuffer, 0, UDP_TX_PACKET_MAX_SIZE); // read the packet into packetBufffer and get the senders IP addr and port number Udp.read(packetBuffer,UDP_TX_PACKET_MAX_SIZE); Serial.println("Contents:"); Serial.println(packetBuffer); analogWrite(9, atoi(packetBuffer)); //utiliser la valeur reçu pour allumer la led } //delay(250); } </code> PHP script for udp : <code> <?php
$valeur_led = $_POST["led1"]; // récupération de la valeur transmise en méthode POST $host="88.167.XXX.XXX"; // Adresse ip défini dans le code arduino $port=8888; // Port défini dans le code arduino
$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); socket_sendto($socket, $valeur_led , strlen($valeur_led), 0, $host, $port); socket_close($socket);
?>
An Idea? Thank u for your help
|
|
|
|
|
14
|
Forum 2005-2010 (read only) / Français / Re: entrée analogue trop changeante
|
on: September 02, 2010, 01:45:53 pm
|
coté montage c est vraiment ce qu il y a de plus simple: Le Gnd à la patte basse du potentiometre, le 5v à la patte haute et l analogue pour la lecture à la patte du milieu.
salut, Je me trompe ou c'est une super facon de mettre l'alim en court-circuit quand le potar est en butée d'un coté??? @+ 
|
|
|
|
|
15
|
Forum 2005-2010 (read only) / Français / Re: nrf24l01+ problème de portée Wifi
|
on: September 01, 2010, 03:13:14 pm
|
Bonjour Teiva, Merci pour la réponse, qui m'éclaire déjà sur une chose, la portée envisageable. Voici le module que j utilise :  j en ai commandé 2 autres de ce type :  en espérant avoir un peu plus de portée. Pour répondre à ta question, j ai effectivement essayé l'exemple du ping mais j ai rapidement changé le prog car il faut allumer dans l ordre récepteur puis emetteur et si la liaison est perdue, elle ne repart pas sans faire un reset de l emetteur... Pas très pratique pour le test de portée. J aimerai obtenir une liaison d'environ 20 metres, ca me suffirait. J ai essayé le canal 2 et le canal 140, est ce que ca vaut le coup de tenter les autres? j ai une freebox qui tourne en serveur wifi @+
|
|
|
|
|