Networking with Arduino
18:06 04 Oct 2017

I am trying to communicate between my local environment and a friend's Arduino board connected to the internet by an ESP8266 wifi chip and port forwarding.

If I execute a command, the command is received by the ESP and passed to the Arduino, where it is executed based on a corresponding function.

What I am looking to do have the ESP return the reading to my machine ('the web server') in JavaScript.

I was hoping to use Axios for promise-based HTTP/S requests. The action I send from Axios is being registered on the board and the action is being completed and returning HTML to the webpage when I visit the IP/URL in the browser, but how can I get a successful or error response from Arduino in the Axios response i.e. JavaScript?

function_on() {
  var ArduinoVar = "http://" + this.ip + ":80";
  axios.get(ArduinoVar, {
    // cm1 is a function on Arduino, processed after 2 seconds
    params: {
      "cm1": 2000
    }
  })

  // The error was being handled here. I have since implemented CORS to manage pre-flight requests and now the error is not being hit anymore.
  .then(response => {
    console.log('response');
    console.log(response);
  })
  .catch(error => {
    console.log('error');
    console.error(error);
  });
  {Conection: close};

The Arduino code is set up to client.println "On 1" or "Off 0" to the browser when the function is hit. If I visit my friends IP, this works fine.

How can I register this with a response in JavaScript?

laravel http arduino vue.js axios