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 " "; 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 ethernetUdp.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);*
}
[/quote]
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