/** based on http://www.exampledepot.com/egs/java.net/Post.html */
  private long getNewRobotUID() {
    long new_uid = 0;

    try {
      // Send data
      URL url = new URL("https://marginallyclever.com/stewart_platform_getuid.php");
      URLConnection conn = url.openConnection();
      try (final InputStream connectionInputStream = conn.getInputStream();
          final Reader inputStreamReader = new InputStreamReader(connectionInputStream);
          final BufferedReader rd = new BufferedReader(inputStreamReader)) {
        String line = rd.readLine();
        new_uid = Long.parseLong(line);
      }
    } catch (Exception e) {
      e.printStackTrace();
      return 0;
    }

    // did read go ok?
    if (new_uid != 0) {
      // make sure a topLevelMachinesPreferenceNode node is created
      // tell the robot it's new UID.
      this.sendLineToRobot("UID " + new_uid);
    }
    return new_uid;
  }
  @Override
  // override this method to check that the software is connected to the right type of robot.
  public void dataAvailable(AbstractConnection arg0, String line) {
    if (line.contains(hello)) {
      isPortConfirmed = true;
      // finalizeMove();
      setModeAbsolute();
      this.sendLineToRobot("R1");

      String uidString = line.substring(hello.length()).trim();
      System.out.println(">>> UID=" + uidString);
      try {
        long uid = Long.parseLong(uidString);
        if (uid == 0) {
          robotUID = getNewRobotUID();
        } else {
          robotUID = uid;
        }
        updateGUI();
      } catch (Exception e) {
        e.printStackTrace();
      }

      displayName = "Rotary Stewart Platform 2 #" + robotUID;
    }
  }