Running code from web hosted text file

Is there a way to run code from a text file hosted on a public server when the number of lines might be unknown or change? I know you can "read" the text file and extract "rows" but I want to load the entire file "as-is" into a function.

Arduino code must be compiled before it is uploaded to an Arduino. The program text that you write is never put in the Arduino so I think the answer to your question is NO.

More information would help.

...R

What do you mean by 'running code'? You have e.g. an ino file that you want to execute? Or you have your own 'language' with simple commands (e.g. ledOn(13), ledOff(13)).

For the first one, ino files need to be compiled to an executable that needs to be programmed in the flash memory of the Arduino micro controller. For the second one, you need to write a interpreter; definitely possible (in general not the easiest of tasks depending on the complexity) but it needs to be simple if you take into account the memory constraints of your Arduino.

while(client.connected() && !client.available()) delay(1); //waits for data
  while (client.connected() || client.available()) { //connected or data available
    char c = client.read(); //gets byte from ethernet buffer
    Serial.print(c); //prints raw feed for testing
    if (c==lf) x=(x+1); //counting line feeds
    if (x==9) readString += c; //building readString
   }

With this snippet of code, the text file is output to serial from the "print(c)" command. So there is no way of making it control a led for example?

The text file contents are:

digitalWrite(relay1, HIGH);
delay(500);
digitalWrite(relay1, LOW);
delay(500);

the text file is output to serial from the "print(c)" command.

It's also collected in the readString variable.

So there is no way of making it control a led for example?

Yes, there is. You get to write the parser. You get to convert the parsed tokens into usable machine control data.

That's all that a compiler does. So, start writing one.

Pretty quickly, you'll see that the job becomes incredibly complicated. Developing a simpler representation of the instructions you want to be able to execute from the text file will be the next step. That is what bitlash did, when they faced reality.

Have a look at the parse example in Serial Input Basics and, as @PaulS has suggested, devise a simple system for defining the data the Arduino will act on. For the example you have shown in Reply #3 it could be

<1,500>
<0,500>

...R

That link was very helpful. Thank you. :slight_smile: