Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 3 of 3

Thread: Pinging Multiple T4.1s via UDP+OSC

  1. #1
    Junior Member
    Join Date
    Feb 2021
    Posts
    2

    Pinging Multiple T4.1s via UDP+OSC

    Hello - I am having problems pinging multiple T4.1s on the same network via UDP and the OSC library from CNMAT.

    I have simplified my sketch to only include the UDP/OSC comms between two T4.1s and host computer. It appears that the Udp.parsepacket() function performs as expected for one T4.1 on the network while the other device doesn't read any data at the udp.parsepacket() call. Whichever device was flashed last is the one that is communicating without problems.

    I'm wondering if there's something obvious I'm missing or if others can reproduce this scenario.

    I'm using Touchdesigner to send and receive OSC, but have also tested with Max/MSP with the same results. The T4.1s and host computer are the only devices connected to the network.

    General setup:
    MacBookPro, OS 10.14.6
    Touchdesigner 099, build 2020.22080
    Max/MSP, v8.1.5
    Teensyduino 1.53 & 1.54 beta #3
    Netgear GS305 network switch

    Code:
    #include <NativeEthernet.h>
    #include <NativeEthernetUdp.h>
    #include <OSCBundle.h>
    
    // ETHERNET STUFF
    EthernetUDP Udp;
    OSCBundle bndl_ping;
    IPAddress hostIP(10, 0, 1, 65);       // HOST IP
    
    IPAddress teensyIP(10, 0, 1, 201);    // Teensy #1 IP address
    int localPort = 9011;                 // Teensy #1 local port
    int hostPort = 9001;                  // Teensy #1 host port
    
    //IPAddress teensyIP(10, 0, 1, 202);  // Teensy #2 IP address
    //int localPort = 9012;               // Teensy #2 local port
    //int hostPort = 9002;                // Teensy #2 host port
    
    int size;
    
    // MAC ADDRESS
    #if defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MKL26Z64__)
    static byte mac[6];
    void read(uint8_t word, uint8_t *mac, uint8_t offset) {
      * FTFL_FCCOB0 = 0x41; * * * * * * // Selects the READONCE command
      * FTFL_FCCOB1 = word; * * * * * * // read the given word of read once area
    
      * // launch command and wait until complete
      * FTFL_FSTAT = FTFL_FSTAT_CCIF;
      * while (!(FTFL_FSTAT & FTFL_FSTAT_CCIF));
    
      * *(mac + offset) = * FTFL_FCCOB5; * * *    // collect only the top three bytes,
      * *(mac + offset + 1) = FTFL_FCCOB6; * * *  // in the right orientation (big endian).
      * *(mac + offset + 2) = FTFL_FCCOB7; * * *  // Skip FTFL_FCCOB4 as it's always 0.
    }
    void read_mac() {
      * read(0xe, mac, 0);
      * read(0xf, mac, 3);
    }
    #else
    void read_mac() {}
    byte mac[] = {
      0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
    };
    #endif
    
    void setup()
    {
      delay(1000);
      
      // SERIAL
      Serial.begin(115200);
    
      // UDP STUFF
      Ethernet.begin(mac, teensyIP);
      Udp.begin(localPort);
      Serial.println("teensy has arrived");
    }
    
    void loop()
    {
    
      OSCBundle bndlReceived;
      
      // receive a bundle
      if ( (size = Udp.parsePacket()) > 0)
      {
        Serial.print("bundle size: ");
        Serial.println(size);
    
        while (size--)
          bndlReceived.fill(Udp.read());
    
        if (!bndlReceived.hasError())
        { 
          if (bndlReceived.size() > 0)
          {
            bndlReceived.dispatch("/ping", ping);
            
          }
        }
      }
    }
    
    void ping(OSCMessage &msg)
    {
        Serial.println("ping requested");
        
        bndl_ping.add("/pingReceived ");
        Udp.beginPacket(hostIP, hostPort);
        bndl_ping.send(Udp);
        Udp.endPacket();
        bndl_ping.empty();
    }

  2. #2
    Senior Member vjmuzik's Avatar
    Join Date
    Apr 2017
    Posts
    822
    The MAC address code you are using doesn’t support a Teensy 4.1 so all your Teensy’s are trying to communicate with the same address(0XDEADBEEFFEED).
    The code you want for a Teensy 4.1 is this:
    Code:
    uint8_t mac[6];
    void teensyMAC(uint8_t *mac) {
        for(uint8_t by=0; by<2; by++) mac[by]=(HW_OCOTP_MAC1 >> ((1-by)*8)) & 0xFF;
        for(uint8_t by=0; by<4; by++) mac[by+2]=(HW_OCOTP_MAC0 >> ((3-by)*8)) & 0xFF;
        Serial.printf("MAC: %02x:%02x:%02x:%02x:%02x:%02x\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
    }

  3. #3
    Junior Member
    Join Date
    Feb 2021
    Posts
    2
    Yes, that's exactly it. Thank you!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •