You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • Thanks!

    Well, as you're using PHP on the Pi, you can actually do echo $_SERVER['REMOTE_ADDR'];, which will get the IP address of the computer that accessed the webpage. In some ways that might be easier.

    But to do what you want on the Pico, you can do:

    wifi.getIP(function(err,ip) {
      if (err) return;
      require("http").get("http://192.168.0.2/­get_pico_ip.php?picoid=pico001&ip="+ip, function(res) {
       // ...
      });
    });
    

    Just in case it's helpful, there's also process.env.SERIAL on the Pico, which gives you the (hopefully unique) serial number of the microcontroller. It might mean you can use exactly the same code for multiple Picos.

    edit: just to add that this could be a bit more tricky because I'm not 100% sure you can have an HTTP server and a client at the same time on the ESP8266. You'd need to make sure you only started the server after the HTTP request closed.

  • Thanks Gordon,

    It was actually the fact that you suggested in your guide that you are not able to have a server and client running at the same time that prompted the question.

    So, the php remote address is neat, I should of known that. But to stamp it to a unique ID (like the board SN) a client call would be needed first anyway.

    To make this work, I would call the function above first to establish the connection to the Pi / register with the Pi that the Pico exists and is available for communicating, then start the server and listen for commands. Sounds OK to me.

    Thanks for the tips, I will experiment...

About

Avatar for Gordon @Gordon started