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.