-->
Page 1 of 14

How to use local Cloud update of own code

PostPosted: Tue Nov 25, 2014 7:24 pm
by Bananis
As cloud updating is faster and simpler than cable updating, I worked out a way to use it for my locally built and modded AT based firmware.

First some background and a warning. Cloud updating works by pulling one of two firmware files, user1.bin or user2.bin from the iot.espressif.cn server, depending on which one is currently in use on your device. The two images are built of the same object code but linked with different versions of eagle.app.v6.appx.ld to be loaded on different flash positions, 0x01000 (user1.bin) or 0x41000 (user2.bin). A special extra boot loader, boot_v1.1.bin, is needed on addres 0x00000 to select which firmware to run.

Watch out as the SDK can generate both single firmware versions and firmwares supporting cloud update. Both have the AT+CIUPDATE command, but running it on a device with a firmware not generated for cloud update will brick it and then you'll need to reflash it. Make sure you have a firmware supporting cloud update on your device first. This link tells you how you do this: http://blog.electrodragon.com/cloud-updating-your-wi07c-esp8266-now/

This is how to do it:

First you need to set up a web server on your local machine to host the two firmware files user1.bin and user2.bin for your local cloud. I use the IIS7 web swerver as I have Win 7 Pro on my machine and all I had to do was to enable it. This is a great tutorial on how to enable your web server on Windows: http://iamsrijon.wordpress.com/2010/01/25/how-to-install-internet-information-services-iis-7-on-windows-7-ultimate/

in C:\inetpub\wwwroot\ (or wherever you got your inetpub), create the directory tree: v1\device\rom

In the v1\device\rom\ directory, store the default.aspx file (packed and attached to this post as default.rar)
Also in that directory, create links to the two images generated by the SDK dev. env. I got my VM Ubuntu share at C:\Work\ESP8266\Share and use the latest 0.9.3 SDK from Espressif

Code: Select allC:\inetpub\wwwroot\v1\device\rom>mklink user1.bin C:\Work\ESP8266\Share\esp_iot_sdk_v0.9.3\bin\upgrade\user1.bin
C:\inetpub\wwwroot\v1\device\rom>mklink user2.bin C:\Work\ESP8266\Share\esp_iot_sdk_v0.9.3\bin\upgrade\user2.bin


Remember to turn off/configure your fire wall to let the device connect to your new web server.

Now you just need to change the code a bit:

Change the at_exeCmdUpdate function in at_ipCmd.c as below. My local server IP is 192.168.0.178. Use your own IP addr.

Code: Select allvoid ICACHE_FLASH_ATTR
at_exeCmdUpdate(uint8_t id)
{
  pespconn = (struct espconn *)os_zalloc(sizeof(struct espconn));
  pespconn->type = ESPCONN_TCP;
  pespconn->state = ESPCONN_NONE;
  pespconn->proto.tcp = (esp_tcp *)os_zalloc(sizeof(esp_tcp));
  pespconn->proto.tcp->local_port = espconn_port();
  pespconn->proto.tcp->remote_port = 80;

  specialAtState = FALSE;
//  espconn_gethostbyname(pespconn, "iot.espressif.cn", &host_ip, upServer_dns_found);

// Do not use the DNS lookup + callback above.
// Instead connect directly to local server IP:

  uart0_sendStr("+CIPUPDATE:1b\r\n");
  if(host_ip.addr == 0 )
  {
    *((uint8 *) &pespconn->proto.tcp->remote_ip)     = 192; //Host IP = 192.168.0.178
    *((uint8 *) &pespconn->proto.tcp->remote_ip + 1) = 168;
    *((uint8 *) &pespconn->proto.tcp->remote_ip + 2) = 0;
    *((uint8 *) &pespconn->proto.tcp->remote_ip + 3) = 178;

    espconn_regist_connectcb(pespconn, at_upDate_connect_cb);
    espconn_regist_reconcb(pespconn, at_upDate_recon_cb);
    espconn_connect(pespconn);
  }
}


Also add this line to the end of the at_upDate_recv function also in at_ipCmd.c

Code: Select allespconn_disconnect(pespconn);


This is needed as I haven't found a way for the web server to disconnect the client like the espessif server does. This is important as it's the disconnection of the first request will trigger the actual downloading.


That's it.

To build the two firmware files, use the gen_misc_plus.sh script. There is a bug in the make file, so it will not link unless anything is changed, resulting in identical user1.bin and user2.bin files so to make it link just remove libuser.a first.

Code: Select allrm ./user/.output/eagle/debug/lib/libuser.a
./gen_misc_plus.sh 1
rm ./user/.output/eagle/debug/lib/libuser.a
./gen_misc_plus.sh 2



It would probably be easy to add a check for new FW on boot of the device, simplifying the process even further.

/Bananis

Re: How to use local Cloud update of own code

PostPosted: Wed Nov 26, 2014 2:33 am
by alonewolfx2
Thank you for good instruction. I will test it.

Re: How to use local Cloud update of own code

PostPosted: Mon Dec 01, 2014 2:34 pm
by bmpenuelas
Great work, I too will try it ASAP!

Re: How to use local Cloud update of own code

PostPosted: Tue Dec 02, 2014 6:31 pm
by Bananis
I got the GCC toolchain to work under Windows/MinGW64 and made a makefile that makes cloud update images (user1.bin and user2.bin), see my post here http://www.esp8266.com/viewtopic.php?f=9&t=224&p=3872#p3872.

/Bananis