ariadne bootloader useful in this project?

Hi guys,

First of all,

I want to send binary sketch from my client to my arduino server.

This is what my Universirty prof. wants me to do

•UPLOAD/EXECUTE PROGRAM
This is to upload a program to the device. The program will be compiled externally using the info collected above. After receiving the program to a suitable region in the memory, the listener program will pass the control to the program. Using a timer, the listener program will wake up periodically and it may check the health of the running program and interrupt if necessary.

My hardwares: Arduino Mega 2560 and ethernet shield w5100

my arduino server code is here , is ariadne bootloader work together?

#include <SPI.h>
#include <Ethernet.h>
#include <ArduinoJson.h>


byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, xx,xx,xx);
IPAddress gateway( 10, 0, 0, 1 );
IPAddress subnet(255, 255, 0, 0);
EthernetServer server(5002);
String inData; //char inData;
int count=0;


void setup() {

 

 // initialize the ethernet device
 Ethernet.begin(mac, ip, gateway, subnet);
 // start listening for clients,
 server.begin();
// Open serial communications and wait for port to open:
 Serial.begin(9600);
 Serial.println(Ethernet.localIP());
  
}

void loop() {
 
 EthernetClient client = server.available();

 // when the client sends the first byte, say hello:
 if (client.connected()) {
while (client.available())
    {
     char thisChar = client.read();
     inData += thisChar;
     // echo the bytes to the server as well:
     Serial.write(thisChar);
     }
    }  
    
  if (inData == "1") {
  StaticJsonDocument<300> doc;
  char json[] ="{\"Model\":\"Arduino MEGA 2560\",\"Microcontroller\":\"Atmega2560\",\"Flash Memory\":\" 256 KB (Atmega2560) 8 KB bootloader\",\"SRAM\":\"8 KB (ATmega2560)\",\"EEPROM\":\"4 KB (ATmega2560)\",\"Clock frequency\":\"16 MHz\",\"Communication types\":\"UART-TTL,USB,I2C,SPI,TCP/IP\"}";  
  DeserializationError error = deserializeJson(doc, json);
  // Test if parsing succeeds.
  if (error) {
    Serial.print(F("deserializeJson() failed: "));
    Serial.println(error.c_str());
    return;
  }

 else
 {
  if(count==0)
  {     
  client.print("Information is ready, write 'OK' ");
  }
  serializeJsonPretty(doc, client);
  count=1;
 }
  }

  
  
  else if(inData!="1" || inData!="OK" )
  { 
    client.print("Any different request?");
    inData="";
  }

inData="";


}

My all project if you need to know:

Topic: Internet of Things

The project is to control small internet devices using a remote program upload and peripharel discovery. A listening program will run in the background and will listen for external commands.

Requirement: The program will listen to a port for external commands and requests. After receiving the command, the listener program will execute the request. It is possible to transfer data in/out the device if necessary. The commands will have a predefined structure whicl should be identifies during the project. The small device can be an Ardunio system although this is not a must.

COMMANDS:

• GET_INFO

This command is sent by an external system to the device. The listening program will collect information about the device it is running on, and using a parsebla format (like XML), it will send it back. Some items can be listed as :

o # of AD converters
o Clock Frequeny
o Chip Model
o # of timers
o Serial/ USB/CAN/I2C communication types
o Size of registers (8,16,32,64)
o ...etc.

• UPLOAD DATA

Using a predefined format, data needs to be passed to the device and a suitable location will be used to store the data. For example

o # of values to be stored
o Set of values
o Location ??? (dynamicly determined)

• DOWNLOAD DATA

Data generated after the running a program, will be transferred using a predefined protocol to external systems.
o Store the generated data to a predefined location. The data will uploaded to an external system upon request.

• UPLOAD/EXECUTE PROGRAM

This is to upload a program to the device. The program will be compiled externally using the info collected above. After receiving the program to a suitable region in the memory, the listener program will pass the control to the program. Using a timer, the listener program will wake up periodically and it may check the health of the running program and interrupt if necessary.

• INTERRUPT PROGRAM

This command will be used to stop the running program.

the assignment doesn't require loading of your sketch over Ethernet

Juraj:
the assignment doesn't require loading of your sketch over Ethernet

Hi juraj, Could you explain more? I was going to use your library, but I guess it was updating all the code.

yes ArduinoOTA too updates the sketch.
but your assignment ask you to write a sketch handling user commands sent over network.
like

Hello, whats your command?
version?
Version is 0.0.1
hardware?
Hardware is Arduino Mega
analogRead(A5)
A5 is 512

and then allow to upload a 'program' with a series of this commands

Juraj:
yes ArduinoOTA too updates the sketch.
but your assignment ask you to write a sketch handling user commands sent over network.
like

Hello, whats your command?
version?
Version is 0.0.1
hardware?
Hardware is Arduino Mega
analogRead(A5)
A5 is 512

Yeap, I'm doing like that but update/execute requirement wants to upload sketch(binary file) over ethernet and execute it. And listener program(arduino server) will run in background and will check health of running sketch which is i uploaded over ethernet.

I already connected server via socket c++ but My problem is sending sketch and execute it.

so ok. you upload a sketch. what will monitor and interrupt it?

Juraj:
so ok. you upload a sketch. what will monitor and interrupt it?

Believe me , i have no idea about it. Someone said this impossible with arduino because "This may not be possible because Arduino do not have a multi-tasking operating system that would be required to achieve that."

I'm confused about this project.

if you remember i posted before, you answered.

https://forum.arduino.cc/index.php?topic=696945.0

learner45:
Believe me , i have no idea about it. Someone said this impossible with arduino because "This may not be possible because Arduino do not have a multi-tasking operating system that would be required to achieve that."

I'm confused about this project.

if you remember i posted before, you answered.

IoT project with arduino. I'm stuck at some commands. - Programming Questions - Arduino Forum

I remember.
I am sure the "UPLOAD/EXECUTE PROGRAM" part is only about user sending a batch of commands.
your interpretation would be an operating system.

When I read this

UPLOAD/EXECUTE PROGRAM

This is to upload a program to the device. The program will be compiled externally using the info collected above. After receiving the program to a suitable region in the memory, the listener program will pass the control to the program. Using a timer, the listener program will wake up periodically and it may check the health of the running program and interrupt if necessary.

it seems to me that they the teacher does want some sort of micro kernel / OS scheduler to be written. That’s an interesting exercise but not trivial.

J-M-L:
When I read this it seems to me that they the teacher does want some sort of micro kernel / OS scheduler to be written. That’s an interesting exercise but not trivial.

Hi J-M-L, thanks for answering. I do not have enough experience with what you are saying.

Did you read all project info? If you have time , could you read and give a advice?

learner45:
My all project if you need to know:

Topic: Internet of Things

The project is to control small internet devices using a remote program upload and peripharel discovery. A listening program will run in the background and will listen for external commands.

Requirement: The program will listen to a port for external commands and requests. After receiving the command, the listener program will execute the request. It is possible to transfer data in/out the device if necessary. The commands will have a predefined structure whicl should be identifies during the project. The small device can be an Ardunio system although this is not a must.

COMMANDS:

• GET_INFO

This command is sent by an external system to the device. The listening program will collect information about the device it is running on, and using a parsebla format (like XML), it will send it back. Some items can be listed as :

o # of AD converters
o Clock Frequeny
o Chip Model
o # of timers
o Serial/ USB/CAN/I2C communication types
o Size of registers (8,16,32,64)
o ...etc.

• UPLOAD DATA

Using a predefined format, data needs to be passed to the device and a suitable location will be used to store the data. For example

o # of values to be stored
o Set of values
o Location ??? (dynamicly determined)

• DOWNLOAD DATA

Data generated after the running a program, will be transferred using a predefined protocol to external systems.
o Store the generated data to a predefined location. The data will uploaded to an external system upon request.

• UPLOAD/EXECUTE PROGRAM

This is to upload a program to the device. The program will be compiled externally using the info collected above. After receiving the program to a suitable region in the memory, the listener program will pass the control to the program. Using a timer, the listener program will wake up periodically and it may check the health of the running program and interrupt if necessary.

• INTERRUPT PROGRAM

This command will be used to stop the running program.

I read what’s written. It’s not a led blinking exercise nor something for programming beginners or people with no understanding of microcontrollers’ architectures.

What’s your background ? What did you study in class and for how long ?

You might want to ask for clarifications to your teacher

J-M-L:
I read what’s written. It’s not a led blinking exercise nor something for programming beginners or people with no understanding of microcontrollers’ architectures.

What’s your background ? What did you study in class and for how long ?

You might want to ask for clarifications to your teacher

I actually did. he wants that "If you can load the arduino server program you wrote as a timer interrupt program, then the program copied and running with ftp continues, the arduino server runs every time the timer expires and checks the status and when it returns, the other program continues."

Is it possible?

your TFTP & supervision code would have to behave as a boot loader to be able to install code to run (the Ariadne Bootloader provides only for uploading and it's beta) and you will need some special compile options to build a relevant binary that could be located where needed... (the Ariadne GitHub provides some info about that)

The boot loader would need to be modified, or maybe one of the timer related function (like the ticker maintaining millis()) to 'supervise' what's going on.

So it might be possible, I never tried, but would require quite advanced hacking and its usage would be heavily limited since your MEGA does not have much memory to start with.

definitely very complicated and totally useless on a MEGA in my opinion (except for the opportunity to learn something about scheduling and micro-controllers)

what hardware does the teacher really recommend ?

J-M-L:
your TFTP & supervision code would have to behave as a boot loader to be able to install code to run (the Ariadne Bootloader provides only for uploading and it's beta) and you will need some special compile options to build a relevant binary that could be located where needed... (the Ariadne GitHub provides some info about that)

The boot loader would need to be modified, or maybe one of the timer related function (like the ticker maintaining millis()) to 'supervise' what's going on.

So it might be possible, I never tried, but would require quite advanced hacking and its usage would be heavily limited since your MEGA does not have much memory to start with.

definitely very complicated and totally useless on a MEGA in my opinion (except for the opportunity to learn something about scheduling and micro-controllers)

what hardware does the teacher really recommend ?

Thank you for reply, i am thankful.

I understand , I will try to achieve the success but it will be complicated for me :slight_smile:

My teacher said you can buy the cheapest arduino , it doesnt matter. I bought a UNO but the usage were limited and I bought mega. I guess he wants to achieve trial project that concept.

with Optiboot 8 it is possible to write to flash from sketch. it is possible to write and run code in flash, but on AVR it must be build by linker for the exact address, but a normal Arduino sketch for ATmega is linked to start on address 0.

so it would be better if the supervisor code would in the bootloader section. you could modify Optiboot.

Juraj:
with Optiboot 8 it is possible to write to flash from sketch. it is possible to write and run code in flash, but on AVR it must be build by linker for the exact address, but a normal Arduino sketch for ATmega is linked to start on address 0.

so it would be better if the supervisor code would in the bootloader section. you could modify Optiboot.

Hi juraj, thank you for helping again

your advice is remained abstract in my head. could you give more detail first of all how can i modify optiboot?

sorry you know I'm newbie.

and

I have a idea. lets say, i set up timer and my arduino server code block as a timer interrupt vector.

My arduino server will be get request from client. when client send sketch to OTEthernet will catch the it and execute it in the sketch codes in loop function. is it can be with OTEthernet ?

thank you!

Respects!

learner45:
Hi juraj, thank you for helping again

your advice is remained abstract in my head. could you give more detail first of all how can i modify optiboot?

sorry you know I'm newbie.

and

I have a idea. lets say, i set up timer and my arduino server code block as a timer interrupt vector.

My arduino server will be get request from client. when client send sketch to OTEthernet will catch the it and execute it in the sketch codes in loop function. is it can be with OTEthernet ?

thank you!

Respects!

it is complicated. there is more then one way. I don't know which one would lead to good result. it would be very hard to debug.

for you, I think, it is impossible. it requires knowledge of MCU details, maybe linker scripts details etc.
how much time do you have for this?

Juraj:
it is complicated. there is more then one way. I don't know which one would lead to good result. it would be very hard to debug.

for you, I think, it is impossible. it requires knowledge of MCU details, maybe linker scripts details etc.
how much time do you have for this?

I understand juraj, thank you.

I have one week for complete it.

I have one week for complete it.

given the type of questions you raise I would agree with @JuraJ - this is out of reach for you in a week.

may be you should focus on the "simpler part", having a program that runs and responds to high level queries like GET_INFO etc and not handle the "UPLOAD/EXECUTE PROGRAM" part.