Has anyone used the ethernet module to upload new firmware images?
I'm looking for references to try and do this for a remote Mega device connected via ethernet.
Mikester
Has anyone used the ethernet module to upload new firmware images?
I'm looking for references to try and do this for a remote Mega device connected via ethernet.
Mikester
I do write EEPROM from ethernet, and could see how a modified bootloader could read the EEPROM for reprogramming data instead of over serial, and then restart the board to execute the new code.
However, the on-chip EEPROM (and FLASH) has a limited amount of writes that can occur - you would want to be aware of those limitations when doing something like that.
That would be great - can you please post a code example? I understand about the limited eeprom writes and it's not really an issue.
Ok, first some background; My use is for a home security system. My MEGA is connected to PIR sensors, door contacts, smoke detectors and has some sensors for flood/heat also. The system is designed to be modular, in that I can disconnect a faulty PIR sensor, or change the trigger value for a that sensor if it goes off all the time, just from viewing pages and posting data on my webserver.
The arduino connects repeatedly to that server, informing the webserver of the status and what zones are triggered. During one of these "pings" to the server, the server returns a code indicating that new configuration is ready to download. The arduino immediately re-connects and downloads it using this procedure.
The code retrieves the EEPROM data bytes and then a byte checksum. I process the buffer first, check if the checksum matches and then if so, write the EEPROM. The failed checksum would repeat the download the next sync period automatically.
#define EEPROM_CONFIG_SIZE 22
if(m_WebClient.connect())
{
m_WebClient.print("POST /Tether/AlarmContact.asmx?Func=GetConfig\r\n");
m_WebClient.print("host: www.webserver.com\r\n\r\n");
delay(1);
// store the data here until we checksum it.
uint8_t *pBuffer = (uint8_t *)malloc(EEPROM_CONFIG_SIZE);
uint8_t *pCur = pBuffer;
// this function reads past the HTTP header. The next read is the first byte of the body-content.
readPastHeader(&m_WebClient);
// EEPROM data here receive from server into buffer
uint8_t bCheck=0;
for(int i=0;i<EEPROM_CONFIG_SIZE;i++)
{
*pCur = m_WebClient.read();
// add that to our very simple checksum.
for(int ic=0;ic<8;ic++)
if((((int)*pCur) & 1<<ic) == (1<<ic))
bCheck++;
pCur++;
}
pCur = pBuffer;
uint8_t bCheckCheck = m_WebClient.read();
// if the checksum matches,
if(bCheck == bCheckCheck)
{
//write the eeprom at our starting configuration address.
int iEepromWritePos = EEPROM_CONFIG_ADDR;
// Write EEPROM loop
for(int i=0;i<EEPROM_CONFIG_SIZE;i++)
EEPROM.write(iEepromWritePos++, *pCur++);
// disconnect.
m_WebClient.stop();
free(pBuffer);
return;
}
free(pBuffer);
}
m_WebClient.stop();
}
There are tons of things I think I would improve, but it works flawlessly so far.
Let me know if you have any questions.
Sweet - thanks - I'll give it a try. Mike