Send serials command to arduino from script in remote server

Hi,

I have this project where I am supposed to be able control a LED light connected to Arduino via remote server. The script, which I can reach to control LED is hosted in host.server.com/myArduinoControl.php (not served by arduino) and the arduino is connected to the internet via ethernet shield somewhere in a different location. Is it possible to send a command to arduino via http from my PHP script? What I have found in the forum is in most cases page served by arduino itself.

Regards

Is it possible to send a command to arduino via http from my PHP script?

The action that happens when a submit button on a form is selected does not have to be a script on the same server. It can be a script on a different server (the Arduino as server). Post your PHP script as it is today.

This is the ajax call to arduino board. (Sometimes this call stuck in pending status (Why?)).

$('#click').click(function() {
        $.ajax({
            'type': "GET",
            'global': false,
            'url': "http://192.168.0.2/?led=1&e"
        });
    });

arduino code:

#include <UIPEthernet.h>

EthernetClient client;
EthernetServer server = EthernetServer(80);

char server[] = "192.168.0.3";

#define LED 2

int status, ledValue = 0;
String led, myStr;
boolean reading = false;

void setup() {
  pinMode(LED, OUTPUT);
  
  Serial.begin(9600);

  connectToInternet();
  server.begin();
}

void connectToInternet() {
  byte mac[] = { 
    0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED   };

  if (Ethernet.begin(mac) == 0) {
    for(;;){
      ;
    }
  }
  Serial.println(Ethernet.localIP());
}

void loop(){
  checkForClient();
  digitalWrite(LED, ledValue);
 
/**
Sending some data to remote server in constant intervals
**/
}

void checkForClient(){
  EthernetClient client = server.available();
  if (client) {
    boolean currentLineIsBlank = true;
    boolean sentHeader = false;
    myStr = "";
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        if(reading && c == ' ') 
          reading = false;
        if(c == '?') 
          reading = true;

        if(reading){
          if (c!='?') {
            myStr += c;
          }
        }

        if (c == '\n' && currentLineIsBlank)  
          break;
        if (c == '\n') {
          currentLineIsBlank = true;
        }
        else if (c != '\r') {
          currentLineIsBlank = false;
        }
      }
    }
    parseReq(myStr); 
    client.stop();   
  } 
}

void parseReq(String str) {
  int startIndex = str.indexOf("led");
  int endIndex = str.indexOf("e");

  String led = str.substring(startIndex + 2, endIndex - 1);
  char temp[4];
  led.toCharArray(temp, sizeof(temp));
  ledValue = atoi(temp);

}

I'm sending some data to remote server from arduino as well. How can I make the arduino receive the request of turning led on/off and send the data without blocking each of the action?

This is the ajax call to arduino board.

I can't see the relationship between this statement and

Is it possible to send a command to arduino via http from my PHP script?

When you get it straight in your mind what you are trying to do, feel free to post again. Perhaps with a block diagram showing the servers, clients, scripts, etc.

Is it possible to send a command to arduino via http from my PHP script?

I don't know about PHP, but pot your arduino URL in the hosted web page and send a GET request to the arduino something like below. The below uses no-ip.com for dynamic DNS with your arduino server operating behind your router on port 84.

client.println("<FORM ACTION='http://andriuskulbis.no-ip.com:84' method=get >");