Catégories
Liens
Avec Pure Data, Arduino, Raspberry Pi, Teensy, …
Bizarrement, certains switch ne permettent pas à certaines cartes Ethernet de communiquer.
Communication Arduino / Pure Data
// TEST RECEPTION/ ENVOI UDP #include <SPI.h> #include <Ethernet.h> #include <EthernetUdp.h> byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; IPAddress ip(192, 168, 1, 102); unsigned int localPort = 8888; char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet, char ReplyBuffer[] = "acknowledged"; // a string to send back EthernetUDP Udp; void setup() { Ethernet.begin(mac,ip); Udp.begin(localPort); Serial.begin(9600); } void loop() { 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[i], DEC); if (i < 3) { Serial.print("."); } } Serial.print(", port "); Serial.println(Udp.remotePort()); // read the packet into packetBufffer Udp.read(packetBuffer,UDP_TX_PACKET_MAX_SIZE); Serial.println("Contents:"); Serial.println(packetBuffer); // send a reply, to the IP address and port that sent us the packet we received //Udp.beginPacket(Udp.remoteIP(), Udp.remotePort()); Udp.beginPacket(Udp.remoteIP(), 5000); Udp.write(ReplyBuffer); Udp.endPacket(); } delay(10); }
Quelques exemples :
Attention, télécharger la bibliothèque ArdOSC modifiée (juste un problème de chemins) : ardosc.zip
// TEST RECEPTION/ENVOIE OSC // from Examples > ArdOSC > OSCArguments #include <SPI.h> #include <Ethernet.h> #include <ArdOSC.h> // ------------ CONFIG --------------- // byte myMac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // MAC address byte myIp[] = { 192, 168, 1, 102 }; // IP int serverPort = 8888; // Receive port int destPort = 9000; // Send port OSCServer server; // to receive messages OSCClient client; // to send messages char oscmsg1[]="/pwm"; char oscmsg2[]="/test"; // ------------ SETUP ------------ // void setup(){ Serial.begin(19200); // for debug Ethernet.begin(myMac ,myIp); server.begin(serverPort); server.addCallback(oscmsg1,&func1); // callback function (receive) } // ------------ LOOP ------------ // void loop(){ if(server.aviableCheck()>0){ //Serial.println("alive! "); } } // --------- FUNCTIONS ------------ // void func1(OSCMessage *_mes){ logIp(_mes); // debug, print IP logOscAddress(_mes); // debug, print Address // Get content message byte *sourceIp = _mes->getIpAddress(); //get source ip address int tmpI=_mes->getArgInt32(0); //get 1st argument(int32) float tmpF=_mes->getArgFloat(1); //get 2nd argument(float) int strSize=_mes->getArgStringSize(2); //get 3rd argument(string) char tmpStr[strSize]; //string memory allocation _mes->getArgString(2,tmpStr); // Send OSC message from received and parsed message OSCMessage newMes; //create new osc message newMes.setAddress(sourceIp,destPort); //set destination ip address & port no newMes.beginMessage(oscmsg2); //set arguments newMes.addArgInt32(tmpI+10); newMes.addArgFloat(tmpF+0.01); newMes.addArgString(tmpStr); client.send(&newMes); //send osc message } // -----TOOLS FUNCTIONS --------- // void logIp(OSCMessage *_mes){ byte *ip = _mes->getIpAddress(); Serial.print("IP:"); Serial.print(ip[0],DEC); Serial.print("."); Serial.print(ip[1],DEC); Serial.print("."); Serial.print(ip[2],DEC); Serial.print("."); Serial.print(ip[3],DEC); Serial.print(" "); } void logOscAddress(OSCMessage *_mes){ Serial.println(_mes->getOSCAddress()); }