Code:
void setup() {
pinMode(GPIO, OUTPUT);
digitalWrite(GPIO, LOW);
Serial.begin(115200);
Statistics: Posted by nopnop2002 — Wed Feb 22, 2023 6:39 pm
Statistics: Posted by Tom83 — Fri Jan 13, 2023 1:13 am
Statistics: Posted by s56ffb — Sun Jan 01, 2023 11:07 pm
qz]Install ESP8266 gcc. See
https://docs.espressif.com/projects/esp ... setup.html
Fetch ESP8266_NONOS_SDK from https://github.com/espressif/ESP8266_NONOS_SDK
Point environment variable ESP_SDK to the SDK directory.
Install esptool.
Statistics: Posted by s56ffb — Wed Dec 21, 2022 3:51 pm
Install ESP8266 gcc. See https://docs.espressif.com/projects/esp ... setup.html
Fetch ESP8266_NONOS_SDK from https://github.com/espressif/ESP8266_NONOS_SDK
Point environment variable ESP_SDK to the SDK directory.
Install esptool.
Statistics: Posted by s56ffb — Sun Dec 18, 2022 7:10 pm
qz]Install ESP8266 gcc. See https://docs.espressif.com/projects/esp ... setup.html
Fetch ESP8266_NONOS_SDK from https://github.com/espressif/ESP8266_NONOS_SDK
Point environment variable ESP_SDK to the SDK directory.
Install esptool.
Statistics: Posted by s56ffb — Sun Dec 18, 2022 5:58 pm
Statistics: Posted by DonP — Fri Dec 02, 2022 3:06 pm
Statistics: Posted by Ronak Jain — Mon Nov 14, 2022 6:08 pm
Statistics: Posted by MehdiSoheili — Sun Nov 13, 2022 8:19 am
Statistics: Posted by AgentSmithers — Thu Nov 03, 2022 3:47 am
Statistics: Posted by johnxue — Wed Oct 19, 2022 12:54 am
Statistics: Posted by rayleong — Mon Oct 17, 2022 5:38 pm
FrenkR wrote:Issue resolved. If you have partition of size 1MB or 2MB, then "irom0_0_seg" address-es are the same for both partitions (looks like 0x1000 or 0x101000 are the same?). If you have 512KB partitions, then you must create LD script with different ROM addresses same way as is in LD files for 1024KB OTA partition segmentation(e.g.eagle.app.v6.new.1024.app1.ld, eagle.app.v6.new.1024.app2.ld).
If you don't do that, then uprading from app1 to app2 with the same bin will work, but if you will empty segment1, bin2 will stop working (which makes sense).
I hope that I saved 3 days of hard work "hunting" all those zillion of exceptions.
Rgds,
Frenk
Statistics: Posted by backupluis — Sat Oct 08, 2022 7:10 pm
Statistics: Posted by backupluis — Sat Oct 08, 2022 6:43 pm
Statistics: Posted by FrenkR — Fri Oct 07, 2022 2:06 am
Code:
#define SYSTEM_PARTITION_OTA_SIZE 0x6A000
#define SYSTEM_PARTITION_OTA_2_ADDR 0x81000
#define SYSTEM_PARTITION_RF_CAL_ADDR 0x1fb000
#define SYSTEM_PARTITION_PHY_DATA_ADDR 0x1fc000
#define SYSTEM_PARTITION_SYSTEM_PARAMETER_ADDR 0x1fd000
#define SYSTEM_PARTITION_CUSTOMER_PRIV_PARAM_ADDR 0x7c000
Code:
Fatal exception (0):
epc1=0x40213e48, epc2=0x00000000, epc3=0x00000000, excvaddr=0x00000000, depc=0x00000000
Fatal exception (0):
epc1=0x40213e48, epc2=0x00000000, epc3=0x00000000, excvaddr=0x00000000, depc=0x00000000
Fatal exception (0):
epc1=0x40213e48, epc2=0x00000000, epc3=0x00000000, excvaddr=0x00000000, depc=0x00000000
Code:
40213e48 <init_bss_data>:
40213e48: fffe61 l32r a6, 40213e40 <print_system_param_sectors+0x18>
40213e4b: fffe41 l32r a4, 40213e44 <print_system_param_sectors+0x1c>
40213e4e: 050c movi.n a5, 0
40213e50: 07b467 bgeu a4, a6, 40213e5b <init_bss_data+0x13>
40213e53: 004452 s8i a5, a4, 0
40213e56: 441b addi.n a4, a4, 1
40213e58: f79467 bne a4, a6, 40213e53 <init_bss_data+0xb>
40213e5b: f00d ret.n
40213e5d: 00 .byte 00
40213e5e: 00 .byte 00
40213e5f: 00 .byte 00
40213e60: 08 90 fe 3f
40213e64: 10 90 fe 3f
40213e68: cc 24 00 40
Statistics: Posted by FrenkR — Wed Oct 05, 2022 9:30 am
Statistics: Posted by Just — Fri Sep 16, 2022 9:20 am
Statistics: Posted by gailu — Fri May 27, 2022 12:13 pm
Statistics: Posted by ESP_Frank — Wed May 18, 2022 4:47 pm
Statistics: Posted by David-OLW — Fri Apr 29, 2022 10:48 pm
Statistics: Posted by HankB — Fri Apr 15, 2022 11:23 am
Statistics: Posted by alexsadi — Mon Mar 21, 2022 1:42 am
Code:
esp_now_add_peer(mac,role,channel,key,size)
Statistics: Posted by dvpe — Fri Mar 04, 2022 6:11 pm
Code:
ets Jan 8 2013,rst cause:0, boot mode:(3,0)
unknown reset
ets_main.c
Code:
vTaskDelay(5000 / portTICK_PERIOD_MS);
esp_deep_sleep(30000000);
Code:
ets Jan 8 2013,rst cause:0, boot mode:(3,0)
unknown reset
ets_main.c
Statistics: Posted by cubic — Wed Feb 16, 2022 2:45 pm
Statistics: Posted by yingzezigai — Tue Feb 15, 2022 4:43 pm
Statistics: Posted by banach87 — Sun Jan 16, 2022 1:18 am
Code:
brlrl
ready
Statistics: Posted by stark2k — Tue Jan 11, 2022 7:45 am
Statistics: Posted by AgentSmithers — Wed Jan 05, 2022 11:57 pm
Statistics: Posted by Inquisitor — Wed Jan 05, 2022 11:39 pm
Statistics: Posted by AgentSmithers — Fri Dec 24, 2021 8:35 am
Statistics: Posted by Inquisitor — Fri Dec 24, 2021 5:50 am
AgentSmithers wrote:Link as promised!
Download OracleBox and you can import the OVA.
https://drive.google.com/file/d/1JrA750 ... sp=sharing
Then import you project folder and compile and your good to go!
Let me know if you need help but that is a fully setup dev. If you need a test project if your having issues let me know and Ill zip one up with a makefile and send that over too.
Statistics: Posted by AgentSmithers — Thu Dec 23, 2021 8:06 am
Statistics: Posted by Inquisitor — Wed Dec 22, 2021 6:41 pm
Statistics: Posted by AgentSmithers — Wed Dec 22, 2021 6:53 am
Statistics: Posted by Inquisitor — Wed Dec 15, 2021 11:28 pm
Statistics: Posted by AgentSmithers — Tue Dec 14, 2021 5:02 am
Statistics: Posted by toxicjv — Mon Dec 13, 2021 7:59 pm
AgentSmithers wrote:
...
API Reference" for 2.2 and compared it to this below (version 2.0, look for 2.1 if you can, I couldn't find it online)
http://www.liot.io/media/liot_esp8266_e ... erence.pdf
In 2.2 I think if my memory serves me correctly they add a few new API commands for the 802.11 to adjust power savings to some extent. I would add those API's into your AP init code and toggle with those Params and see if it resolves your issue. If it does post back here so everyone else can see the result!
Statistics: Posted by Inquisitor — Sat Dec 11, 2021 5:00 am
Code:
#ifndef __accesspoint__
#define __accesspoint__
//#define WifiMemorySpaceSector 0x51
#define WifiMemorySpace 0x63000//0x51000 //Also defined in station.h, make sure they match!
struct Customflashconfig APFlashStationConf;
bool ICACHE_FLASH_ATTR reset_accessPoint()
{
os_printf("[%s][%s][%d]\r\n", __FILE__ ,__func__, __LINE__);
struct Customflashconfig Tempconfig;
Tempconfig.programmed=0;
SpiFlashOpResult SpiReturn = spi_flash_write(WifiMemorySpace+sizeof(APFlashStationConf),(uint32 *)&Tempconfig,sizeof(Tempconfig));
if (SpiReturn == SPI_FLASH_RESULT_OK)
{
os_printf("Accesspoint programmed=0\r\n");
}
else
{
os_printf("Failed to reset Accesspoint\r\n");
}
}
bool ICACHE_FLASH_ATTR isset_accessPoint()
{
os_printf("[%s][%s][%d]\r\n", __FILE__ ,__func__, __LINE__);
struct softap_config softapConfig;
spi_flash_read(WifiMemorySpace+sizeof(APFlashStationConf),(uint32 *)&APFlashStationConf,sizeof(APFlashStationConf));
if(APFlashStationConf.programmed==1)
{
return true;
}
else
{
return false;
}
}
/*
typedef enum _auth_mode {
AUTH_OPEN = 0,
AUTH_WEP,
AUTH_WPA_PSK,
AUTH_WPA2_PSK,
AUTH_WPA_WPA2_PSK
} AUTH_MODE;
*/
void ICACHE_FLASH_ATTR set_accessPoint(char * LSSID, char * LPassword, uint8 Lssid_len, AUTH_MODE Lauthmode, uint8 Lchannel, uint8 Lssid_hidden, uint8 Lmax_connection, uint16 Lbeacon_interval, char * LReserved)
{
os_printf("[%s][%s][%d]\r\n", __FILE__ ,__func__, __LINE__);
struct Customflashconfig Tempconfig;
os_memcpy(&Tempconfig.ssid, LSSID, 32);
os_memcpy(&Tempconfig.password, LPassword, 64);
Tempconfig.ssid_len=os_strlen(LSSID);
Tempconfig.authmode=Lauthmode;
Tempconfig.ssid_hidden=Lchannel;
Tempconfig.max_connection=Lmax_connection;
Tempconfig.beacon_interval=Lbeacon_interval;
wifi_softap_set_config(&Tempconfig);
Tempconfig.programmed=1;
//SpiFlashOpResult SpiReturn = spi_flash_erase_sector(WifiMemorySpaceSector);
SpiFlashOpResult SpiReturn = spi_flash_erase_sector(WifiMemorySpace/SPI_FLASH_SEC_SIZE);
if (SpiReturn == SPI_FLASH_RESULT_OK)
{
os_printf("SPI Flash Erase OK\r\n");
}
SpiReturn = spi_flash_write(WifiMemorySpace+sizeof(APFlashStationConf),(uint32 *)&Tempconfig,sizeof(Tempconfig));
if (SpiReturn == SPI_FLASH_RESULT_OK)
{
os_printf("SPI Flash Write OK\r\n");
}
os_printf("ssid: \"%s\"\npw: \"%s\"\nProgrammed: %d\r\n",Tempconfig.ssid,Tempconfig.password,Tempconfig.programmed);
}
void ICACHE_FLASH_ATTR reload_accesspoint()
{
os_printf("[%s][%s][%d]\r\n", __FILE__ ,__func__, __LINE__);
unload_accesspoint();
init_accesspoint();
}
void ICACHE_FLASH_ATTR unload_accesspoint()
{
os_printf("[%s][%s][%d]\r\n", __FILE__ ,__func__, __LINE__);
os_printf("[%s] wifi_get_opmode() = %d\r\n", __func__, wifi_get_opmode());
if ((wifi_get_opmode() & 2) == 2)
{
wifi_set_opmode_current(wifi_get_opmode() & ~2);
os_printf("AccessPoint Disabled wifi_get_opmode() = %d\r\n", wifi_get_opmode());
}
}
void dhcps_lease_test(void)
{
os_printf("[%s][%s][%d]\r\n", __FILE__ ,__func__, __LINE__);
struct ip_info info;
wifi_softap_dhcps_stop();
IP4_ADDR(&info.ip, 192, 168, 1, 1);
IP4_ADDR(&info.gw, 192, 168, 1, 1);
IP4_ADDR(&info.netmask, 255, 255, 255, 0);
wifi_set_ip_info(SOFTAP_IF, &info);
wifi_softap_dhcps_start();
struct dhcps_lease dhcp_lease;
IP4_ADDR(&dhcp_lease.start_ip, 192, 168, 1, 100);
IP4_ADDR(&dhcp_lease.end_ip, 192, 168, 1, 105);
wifi_softap_set_dhcps_lease(&dhcp_lease);
}
void ICACHE_FLASH_ATTR init_accesspoint(char * password, uint8 maxconnections)
{
os_printf("[%s][%s][%d]\r\n", __FILE__ ,__func__, __LINE__);
//Need to implement APSSID And Password
if ((wifi_get_opmode() & 2) != 2)
{
os_printf("Loading AccessPoint %d -> %d\r\n", wifi_get_opmode(), (wifi_get_opmode() | 2));
wifi_set_opmode_current(wifi_get_opmode() | 2);
dhcps_lease_test();
os_printf("AccessPoint Loaded %d\r\n", wifi_get_opmode());
struct softap_config softapConfig;
spi_flash_read(WifiMemorySpace+sizeof(APFlashStationConf),(uint32 *)&APFlashStationConf,sizeof(APFlashStationConf));
APFlashStationConf.ssid[31]=0;
APFlashStationConf.password[63]=0;
//wifi_set_opmode_current(WifiOpMode); //Need to add this to turn on AP
if(APFlashStationConf.programmed==1)
{
os_printf("Saved Information Found for AP!!\r\nssid: \"%s\"\npw: \"%s\"\n SizeOf(APFlashStationConf) = %d\r\n", APFlashStationConf.ssid, APFlashStationConf.password, sizeof(APFlashStationConf));
os_memcpy(&softapConfig.ssid, APFlashStationConf.ssid, 32);
os_memcpy(&softapConfig.password, APFlashStationConf.password, 64);
softapConfig.ssid_len=APFlashStationConf.ssid_len;
softapConfig.authmode=APFlashStationConf.authmode;
softapConfig.ssid_hidden=APFlashStationConf.ssid_hidden;
softapConfig.max_connection=APFlashStationConf.max_connection;
softapConfig.beacon_interval=APFlashStationConf.beacon_interval;
wifi_softap_set_config(&softapConfig);
}
else
{
os_printf("Saved Information Not Found for AP, Using Defaults!!\r\n");
//Set AP Settings
char APssid[32] = "ESP ";
char MACADDR[6];
wifi_get_macaddr(SOFTAP_IF, MACADDR);
char MACADDRFormatted[12];
os_sprintf(MACADDRFormatted,"%02x%02x%02x%02x%02x%02x", MACADDR[0], MACADDR[1], MACADDR[2], MACADDR[3], MACADDR[4], MACADDR[5]);
strcat(APssid, MACADDRFormatted);
//strcat(APssid, MAC2STR(bss_link->bssid))
//char APpassword[64] = "01234567"; //This should be defined by a function argument!!
char APpassword[64] = {0};
if (password != NULL)
{
softapConfig.authmode=AUTH_WPA_WPA2_PSK;
os_printf("Copying AP Password: %s\r\n", password);
os_strcpy(APpassword, password);
}
else
{
softapConfig.authmode=AUTH_OPEN;
os_printf("No AP Password specificied, Leaving AP Open\r\n");
}
os_memcpy(&softapConfig.ssid, APssid, 32);
//os_memcpy(&softapConfig.ssid, "bibo", 32);
os_memcpy(&softapConfig.password, APpassword, 64);
softapConfig.ssid_len=0;
softapConfig.ssid_hidden=0;
softapConfig.max_connection=maxconnections;
softapConfig.beacon_interval=100;
wifi_softap_set_config(&softapConfig);
os_printf("Access Point Up - %s!!\r\n", &softapConfig.ssid); //APssid
}
}
else
{
os_printf("AP Already Loaded");
}
}
#endif
Statistics: Posted by AgentSmithers — Thu Dec 09, 2021 5:14 pm
Code:
#ifndef __httpPostFota__
#define __httpPostFota__
#include <upgrade.h>
//#define UPGRADE_DEBUG
#ifdef UPGRADE_DEBUG
#define UPGRADE_DBG os_printf
#else
#define UPGRADE_DBG
#endif
#define FOTAHTMLSIZE 8192
typedef void (*FOTAWebRecvFunctionCallback)(void *arg, char *pusrdata, unsigned short length);
FOTAWebRecvFunctionCallback FOTAWebRecvCallBack;
unsigned char * FOTAFormatedHTMLPageWithHttpHeader;
LOCAL struct espconn FOTAWebServerSocket;
static char *FOTAmsg_espconn_state[] =
{
"NONE",
"WAIT",
"LISTEN",
"CONNECT",
"WRITE",
"READ",
"CLOSE"
};
char * FOTAHttpHeader = "HTTP/1.1 200 OK\r\nContent-Length: %d\r\nConnection: close\r\n\r\n";
LOCAL void ICACHE_FLASH_ATTR FOTAHttpSendWithHeader(struct espconn * WifiScanConfigConnection, unsigned char * LFormatedHTMLPage) //This may be able to be merged
{
FOTAFormatedHTMLPageWithHttpHeader = (unsigned char*)os_zalloc(FOTAHTMLSIZE);
if (FOTAFormatedHTMLPageWithHttpHeader == 0x0)
{
os_printf("[%s][%s][%d] - Unable to Alloc memory, exiting\r\n", __FILE__ ,__func__, __LINE__);
return;
}
os_printf("Attaching header and sending\r\n");
os_memset(FOTAFormatedHTMLPageWithHttpHeader, 0, FOTAHTMLSIZE);
os_printf("Attaching header and sending\r\n");
os_sprintf(FOTAFormatedHTMLPageWithHttpHeader, FOTAHttpHeader, os_strlen(LFormatedHTMLPage));
os_printf("Attaching header and sending\r\n");
os_strcat(FOTAFormatedHTMLPageWithHttpHeader, LFormatedHTMLPage);
os_printf("Attaching header and sending\r\n");
espconn_send(WifiScanConfigConnection, (uint8*)FOTAFormatedHTMLPageWithHttpHeader, os_strlen(FOTAFormatedHTMLPageWithHttpHeader));
os_printf("HTTP Response sent bytes: %d\r\n", os_strlen(LFormatedHTMLPage));
os_free(FOTAFormatedHTMLPageWithHttpHeader);
}
LOCAL os_timer_t Firmware_Timer;
static ETSTimer http2spi_flash_reboot_timer;
LOCAL char* ICACHE_FLASH_ATTR http2spi_checkheader(void *buf, int which)
{
os_printf("[%s]\r\n", __func__);
uint8_t *cd = (uint8_t *)buf;
uint32_t *buf32 = buf;
os_printf("OTA hdr %p: %08lX %08lX %08lX %08lX\n", buf,
(long unsigned int)buf32[0],
(long unsigned int)buf32[1],
(long unsigned int)buf32[2],
(long unsigned int)buf32[3]);
if (cd[0] != 0xEA) return "IROM magic missing";
if (cd[1] != 4 || cd[2] > 3 || (cd[3]>>4) > 6) return "bad flash header";
//if (cd[3] < 3 && cd[3] != which) return "Wrong partition binary";
if (((uint16_t *)buf)[3] != 0x4010) return "Invalid entry addr";
if (((uint32_t *)buf)[2] != 0) return "Invalid start offset";
return NULL;
}
long gstaticContentLength = 0; //This keeps the Content length in mem for the life of the transactions
long gContentLength = 0; //This is a countdown of Binary Data left to transmit to the client, this includes the Mime header data! Anything after first CRLFCRLF basiclly
uint16 RemotePortsOpenedInDownload = 0; //Only One port at a time can upload a firmware
bool HeaderRead = false;
int dataparts = 0; //This track the file transfer progress in packets
char FOTAdatabuffer[4] = {0}; //Rolling Ring Buffer
uint32 FOTAdatabufferindex = 0;
uint32_t FOTAburnto = 0x0;
uint32_t gOffset = 0x0;
LOCAL void ICACHE_FLASH_ATTR FOTAWebServerConn_recv_callback(void *arg, char *pusrdata, unsigned short length)
{
bool unloadafter = false;
struct espconn * FOTApespconn = (struct espconn *) arg;
//os_printf("[%s] Client recv'ed from port: ", __func__);
/*
uint16_printf(FOTApespconn->proto.tcp->remote_port);
os_printf(" - ");
uint16_printf(FOTApespconn->proto.tcp->local_port);
/*
//os_printf(FOTApespconn->proto.tcp->client_port);
//os_printf(FOTApespconn->tcp.client_port); //How to identify which socket is triggering this WebServerCallback. What if multiple clients are connected?
os_printf("\r\n");
/*
char* getpost = strstr(pusrdata, "POST /upload");
if (getpost != NULL)
{
}
*/
if (RemotePortsOpenedInDownload == FOTApespconn->proto.tcp->remote_port)
{
//os_printf("Incoming file data gcontentlength = %u lCurrentIncomming: %u\r\n", gContentLength, length);
if (dataparts <= 6)
{
dataparts++;
//os_printf(pusrdata);
//hex_printf(pusrdata, length);
//os_printf("\r\n-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\r\n");
}
char * Ptr = pusrdata;
if (HeaderRead == false) //Move past the header
{
os_printf("Header removed\r\n");
while (!strstarts(Ptr, "\r\n\r\n"))
{
Ptr++; //Increment Ptr
//lengthleft--;
}
while (*Ptr == '\n' || *Ptr == '\r')
{
Ptr++; //Increment Ptr
//lengthleft--;
}
os_printf("%u - %u!\r\n", Ptr, pusrdata);
os_printf("Before %u!\r\n", length);
length -= Ptr-pusrdata;
gContentLength -= length;
os_printf("After removing headers %u! Updating gContentLength(%u)\r\n", length, gContentLength);
HeaderRead = true;
}
//os_printf("---");
//os_printf(Ptr);
//os_printf("gcontentlength(%d) - thispacketLength(%d) = %d remainding, DbufferIndex(%u)\r\n", gContentLength, length, (gContentLength - length), FOTAdatabufferindex);
unsigned short i,ii = 0;
for (i=0; i<length; i++)
{
/*
if (i == 0)
{
for (ii=0; ii<10; ii++)
{
os_printf("%x ", *(Ptr + ii));
}
os_printf("\r\n");
}
*/
if (gContentLength < 3000)
{
if (*(Ptr + i) == '-' && *(Ptr + i + 1) == '-' && *(Ptr + i + 2) == '-' && *(Ptr + i + 3) == '-' && *(Ptr + i + 4) == '-' && *(Ptr + i + 5) == '-')
{
//os_printf("Found Hyphens EOF -\r\n");
char * ResponseToSend = "<!DOCTYPE html><html><head><meta http-equiv=\"refresh\" content=\"3;URL='/'\"></head><body>File Uploaded</body></html>";
FOTAHttpSendWithHeader(FOTApespconn, ResponseToSend);
system_update_cpu_freq(80);
return;
}
}
//os_printf("i=%d", i);
system_soft_wdt_feed();
FOTAdatabuffer[FOTAdatabufferindex%4] = *(Ptr + i);
FOTAdatabufferindex++;
if (FOTAdatabufferindex%4 == 0)
{
system_soft_wdt_feed();
if (spi_flash_write(gOffset, (uint32 *)&FOTAdatabuffer, 4) == SPI_FLASH_RESULT_OK)
{
if (gOffset % 0x10000 == 0)
{
os_printf("%u of packet %u - %x %x %x %x Writen to offset 0x%x bin=0x%x bytesleft=%u!\r\n", i, length, FOTAdatabuffer[0], FOTAdatabuffer[1], FOTAdatabuffer[2], FOTAdatabuffer[3], gOffset, gOffset-FOTAburnto, gContentLength-FOTAdatabufferindex);
}
if (gstaticContentLength - FOTAdatabufferindex < 0x30)
{
//os_printf("%u of packet %u - %x %x %x %x Writen to offset 0x%x bin=0x%x bytesleft=%u!\r\n", i, length, databuffer[0], databuffer[1], databuffer[2], databuffer[3], gOffset, gOffset-FOTAburnto, gContentLength-FOTAdatabufferindex);
}
if (FOTAdatabufferindex > gContentLength - 0x10 || FOTAdatabufferindex < 0x10 )// || i < 0x100 //This does for every packet
{
//os_printf("%u of packet %u - %x %x %x %x Writen to offset 0x%x bin=0x%x bytesleft=%u\r\n", i, length, databuffer[0], databuffer[1], databuffer[2], databuffer[3], gOffset, gOffset-FOTAburnto, gContentLength-FOTAdatabufferindex);
}
gOffset += 4;
}
else
{
os_printf("failed writing length:%d\r\n", length);
}
}
if (FOTAdatabufferindex > 60)
{
//return;
}
}
gContentLength -= length;
//os_printf("Packet Processed ContentLength(%u) of packet FOTAdatabufferindex(%u) Difference(%u)\r\n", gstaticContentLength, FOTAdatabufferindex, (gstaticContentLength - FOTAdatabufferindex));
if (gContentLength == 0)
{
//espconn_disconnect(&FOTAWebServerSocket); //Webservers don't close sockets, clients do
char * ResponseToSend = "<!DOCTYPE html><html><body>File Uploaded</body></html>";
FOTAHttpSendWithHeader(FOTApespconn, ResponseToSend);
}
}
if (strstr(pusrdata, "POST /upload") != NULL)
{
system_update_cpu_freq(160);
dataparts = 1;
RemotePortsOpenedInDownload = FOTApespconn->proto.tcp->remote_port;
os_printf(pusrdata);
int index = 0;
char * Ptr = pusrdata;
while (!strstarts(Ptr, "Content-Length: "))
{
Ptr++; //Increment Potr
}
while (*Ptr != ' ')
{
Ptr++; //Increment Potr
}
Ptr++; //Increment to Content String
char ContentLength[8] = {0};
index = 0;
while (*Ptr != '\r' && *Ptr != '\n')
{
ContentLength[index] = *Ptr;
index++;
Ptr++; //Increment Potr
}
os_printf(ContentLength);
gContentLength = atoi(ContentLength);
gstaticContentLength = gContentLength;
Ptr = pusrdata; //Reset PTR
while (!strstarts(Ptr, "Content-Type: multipart/form-data; boundary="))
{
Ptr++; //Increment Potr
}
while (*Ptr != '=')
{
Ptr++; //Increment Potr
}
Ptr++; //Increment to Content String
char Boundary[64] = {0};
index = 0;
while (*Ptr != '\r' && *Ptr != '\n')
{
Boundary[index] = *Ptr;
index++;
Ptr++; //Increment Ptr
//os_printf("%u\r\n", Ptr);
}
Boundary[index] = 0; //This may not be needed by the way I declared boundary with = {0}
os_printf(Boundary);
os_printf("\r\n");
while (!strstarts(Ptr, "\r\n\r\n"))
{
Ptr++; //Increment Ptr
//os_printf("%u\r\n", Ptr);
}
Ptr += 4;
os_printf("HEAD Content Length of file: %d\r\n", gContentLength); //Start erasing the flash at a given address
if(system_upgrade_userbin_check() == 0)
{
FOTAburnto = 0x101000;
}
else
{
FOTAburnto = 0x1000;
}
gOffset = FOTAburnto;
uint32_t poffset = 0x0;
for (poffset=0x0; gContentLength-poffset>0; poffset++)
{
if ((FOTAburnto+poffset) % SPI_FLASH_SEC_SIZE == 0)
{
//os_printf("Erasing 0x%x\r\n", FOTAburnto+poffset);
spi_flash_erase_sector((FOTAburnto+poffset)/SPI_FLASH_SEC_SIZE); //Doing it here may not be fast enough.
}
}
HeaderRead = false; //SetHeader back to false to prep for incoming header to skip
/*
os_printf("%u\r\n", Ptr);
os_printf("%u\r\n", pusrdata);
os_printf("%u\r\n", (Ptr-pusrdata));
//os_printf("%u\r\n", (pusrdata-Ptr)); //This loops around the interger value giving a result back in the 4millons
os_printf("Length: %u\r\n", length);
os_printf("Logic:%u\r\n", length-(Ptr-pusrdata));
//os_printf("%u\r\n", (&Ptr-&pusrdata)); //We don't really care about the addresses
//os_printf("%u\r\n", (&pusrdata-&Ptr));
*/
if(length-(Ptr-pusrdata) > 0) //It's possible data can be fragmented from the first packet
{
unsigned short packetlen = length-(Ptr-pusrdata);
os_printf("Calling first packet remainding len:%u of %u\r\n", packetlen, length);
FOTAWebServerConn_recv_callback(arg, Ptr, packetlen);//This function normally dosn't get called by chrome being predictable during development, This may change later sadly if IE frags the packets differently
}
else
{
//This is not normally called.
}
}
if (strstr(pusrdata, "GET /favicon.ico HTTP/1.1") != NULL) //Skip FavIcon request
{
espconn_disconnect(&FOTAWebServerSocket);
return;
}
if (strstr(pusrdata, "GET / HTTP/1.1") != NULL) //Display Config request
{
os_printf("[%s]\r\n", __func__);
char * ResponseToSend = NULL;
os_printf("[%s]s\r\n", __func__);
if (system_get_userbin_addr() == 0x0)
{
os_printf("OTA Firmware is not detected, please load the OTA firmware\r\n");
ResponseToSend = "<!DOCTYPE html><html><body>OTA Firmware is not detected, please load the OTA firmware</body></html>";
}
else
{
if(system_upgrade_userbin_check() == 0)
{
ResponseToSend = "<!DOCTYPE html><html><body><form action=\"upload\" method=\"post\" enctype=\"multipart/form-data\">Select image to upload to address 0x101000:<input type=\"file\" name=\"fileToUpload\" id=\"fileToUpload\"><input type=\"submit\" value=\"Upload Image\" name=\"submit\"></form></body></html>";
}
else
{
ResponseToSend = "<!DOCTYPE html><html><body><form action=\"upload\" method=\"post\" enctype=\"multipart/form-data\">Select image to upload to address 0x1000:<input type=\"file\" name=\"fileToUpload\" id=\"fileToUpload\"><input type=\"submit\" value=\"Upload Image\" name=\"submit\"></form></body></html>";
}
}
os_printf("[%s]s1\r\n", __func__);
//espconn_send(FOTApespconn, ResponseToSend, os_strlen(ResponseToSend));
FOTAHttpSendWithHeader(FOTApespconn, ResponseToSend);
os_printf("[%s]s2\r\n", __func__);
}
}
LOCAL void ICACHE_FLASH_ATTR FOTAWebServerConn_connect_callback(void *arg)
{
os_printf("[%s] Client Connected from port: ", __func__);
struct espconn * FOTApespconn = (struct espconn *) arg;
uint16_printf(FOTApespconn->proto.tcp->remote_port);
os_printf(" - ");
uint16_printf(FOTApespconn->proto.tcp->local_port);
os_printf("\r\n");
return;
remot_info *premot = NULL;
uint8 reter = espconn_get_connection_info(FOTApespconn,&premot,0);
if (reter == ESPCONN_OK)
{
if(FOTApespconn->link_cnt)
{
os_printf("EspConn %u TCP connections:\r\n", FOTApespconn->link_cnt);
int i = 0;
while(i < FOTApespconn->link_cnt)
{
os_printf("%d) " IPSTR ":%u %s\r\n", i, IP2STR(premot[i].remote_ip), premot[i].remote_port, FOTAmsg_espconn_state[premot[i].state] );
i++;
};
}
}
else
{
os_printf("EspConn getting TCP connections failed: %d\r\n", reter);
}
}
static ETSTimer http2spi_flash_reboot_timer;
void ICACHE_FLASH_ATTR FOTAWebServerConn_disconnect_callback(void *arg)
{
os_printf("[%s] Client Disconnected from port: ", __func__);
struct espconn * FOTApespconn = (struct espconn *) arg;
uint16_printf(FOTApespconn->proto.tcp->remote_port);
os_printf(" - ");
uint16_printf(FOTApespconn->proto.tcp->local_port);
os_printf("\r\n");
if (RemotePortsOpenedInDownload == FOTApespconn->proto.tcp->remote_port)
{
os_printf("Last Status: gcontentlength(%d), DbufferIndex(%u)\r\n", gContentLength, FOTAdatabufferindex);
uint32 Http2SPI_buf[8];
spi_flash_read(FOTAburnto, Http2SPI_buf, sizeof(Http2SPI_buf));
uint8 id = system_upgrade_userbin_check();
char *err = http2spi_checkheader(Http2SPI_buf, 1-id);
if (err != NULL) {
os_printf("OTA Not a bootable bin, %s\n HTTP to SPI completed.\r\n", err);
return -1;
}
os_printf("Reboot needed, rebooting...");
// Schedule a reboot
system_upgrade_flag_set(UPGRADE_FLAG_FINISH);
os_timer_disarm(&http2spi_flash_reboot_timer);
os_timer_setfn(&http2spi_flash_reboot_timer, (os_timer_func_t *)system_upgrade_reboot, NULL);
os_timer_arm(&http2spi_flash_reboot_timer, 2000, 1);
}
}
void ICACHE_FLASH_ATTR FOTAWebServerConn_sent_callback(void *arg)
{
os_printf("[%s] Data Sent\r\n", __func__);
espconn_disconnect(&FOTAWebServerSocket);
}
void ICACHE_FLASH_ATTR init_FOTAwebserver(uint16 port, void * LFOTAWebRecvCallBack(void *arg, char *pusrdata, unsigned short length)) //LFOTAWebRecvCallBack may need to point to the next pointer of the function and not the parent recv function
{
os_printf("[%s]\r\n", __func__);
//FOTAFormatedHTMLPageWithHttpHeader = (unsigned char*)os_zalloc(FOTAHTMLSIZE); //Never alloc on init. only when the far is used then free it asap!
if (LFOTAWebRecvCallBack != NULL)
{
os_printf("Setting Callback for WebServer\r\n");
FOTAWebRecvCallBack = LFOTAWebRecvCallBack;
}
FOTAWebServerSocket.type = ESPCONN_TCP;
FOTAWebServerSocket.state = ESPCONN_NONE;
FOTAWebServerSocket.proto.tcp = (esp_tcp *)os_zalloc(sizeof(esp_tcp));
if (FOTAWebServerSocket.proto.tcp == 0x0)
{
os_printf("[%s][%s][%d] - Unable to Alloc memory, exiting\r\n", __FILE__ ,__func__, __LINE__);
return;
}
FOTAWebServerSocket.proto.tcp->local_port = port; // ESP8266 tcp port
espconn_accept(&FOTAWebServerSocket); // create tcp
espconn_regist_connectcb(&FOTAWebServerSocket, FOTAWebServerConn_connect_callback);
espconn_regist_recvcb(&FOTAWebServerSocket, FOTAWebServerConn_recv_callback); // register a tcp packet receiving callback
espconn_regist_sentcb(&FOTAWebServerSocket, FOTAWebServerConn_sent_callback);
espconn_regist_disconcb(&FOTAWebServerSocket, FOTAWebServerConn_disconnect_callback);
}
#endif
Statistics: Posted by AgentSmithers — Thu Dec 09, 2021 5:09 pm
Statistics: Posted by AgentSmithers — Thu Dec 09, 2021 4:59 pm
Code:
typedef struct {
uint32 magic ;
uint32 rst_count;
uint64 Reserved;
}RTC_RST_STRUCT;
bool ICACHE_FLASH_ATTR StoreRSTCount(uint32 Count)
{
os_printf("[%s][%s][%d] - creating with: %u\r\n", __FILE__ ,__func__, __LINE__, Count);
//system_rtc_mem_write(68, &Count, sizeof(Count));
RTC_RST_STRUCT rtc_rst;
rtc_rst.magic = 0xDEADBEEF;
rtc_rst.rst_count = Count;
system_rtc_mem_write(72, &rtc_rst, sizeof(rtc_rst));
}
uint32_t ICACHE_FLASH_ATTR GetRSTCount(void)
{
os_printf("[%s][%s][%d]\r\n", __FILE__ ,__func__, __LINE__);
uint32 count;
//system_rtc_mem_read(68, &count, sizeof(count));
RTC_RST_STRUCT rtc_rst;
system_rtc_mem_read(72, &rtc_rst, sizeof(rtc_rst));
if(rtc_rst.magic==0xDEADBEEF)
{
os_printf("[%s][%s][%d] - GET GetRSTCount %u\r\n", __FILE__ ,__func__, __LINE__, rtc_rst.rst_count);
return rtc_rst.rst_count;
}
else
{
return NULL;
}
}
Code:
struct rst_info *rtc_info = system_get_rst_info();
os_printf("reset reason: %x\n", rtc_info->reason);
switch (rtc_info->reason)
{
case REASON_DEFAULT_RST:
os_printf("REASON_DEFAULT_RST\r\n");
break;
case REASON_WDT_RST:
os_printf("REASON_WDT_RST\r\n");
break;
case REASON_SOFT_WDT_RST:
os_printf("REASON_SOFT_WDT_RST\r\n");
break;
case REASON_SOFT_RESTART:
os_printf("REASON_SOFT_RESTART\r\n");
break;
case REASON_EXCEPTION_RST:
os_printf("REASON_EXCEPTION_RST (%d)\r\n", rtc_info->exccause); //Add recovery code logic here
uint32_t EXC = GetEXCCount();
if (EXC == NULL)
{
StoreEXCCount(1);
}
else
{
EXC++;
StoreEXCCount(EXC);
}
//Add some Call back register here! =)
break;
case REASON_DEEP_SLEEP_AWAKE:
os_printf("REASON_DEEP_SLEEP_AWAKE\r\n");
break;
case REASON_EXT_SYS_RST:
os_printf("REASON_EXT_SYS_RST - Button Press\r\n"); //When freshly Flashed we get this or a Hard button Reset
common_RSTCount = GetRSTCount();
if (common_RSTCount == NULL)
{
os_printf("common_RSTCount == NULL / ZERO\r\n");
StoreRSTCount(1);
}
else if(common_RSTCount == 9)
{
os_printf("common_RSTCount == %u, setting up WiFi\r\n", common_RSTCount);
}
else
{
os_printf("common_RSTCount == %u\r\n", common_RSTCount);
common_RSTCount++;
StoreRSTCount(common_RSTCount);
}
delay_5seconds(); //Give the user five seconds to reset once more to higher the count!
//Add some Call back register here! =)
if(common_RSTCount >= 3 || false) //true for debugging code
{
os_printf("Entering Debug Mode");
FlickerLED(2, 30);
FlickerLED(2, 60);
FlickerLED(2, 30);
FlickerLED(2, 60);
//Add some debug code here
spi_flash_read(WifiMemorySpace,(uint32 *)&GlobalFlashConfig,sizeof(GlobalFlashConfig));
uart_init(BIT_RATE_115200, BIT_RATE_115200, &UartReceive); //This only seems to be kicked off via the COM-USB onboard, Not the TX/RX port
InDebugMode = true;
}
StoreRSTCount(0); //Reset value to zero
break;
default:
os_printf("Some other REASON?!\r\n");
break;
}
if (rtc_info->reason == REASON_WDT_RST || rtc_info->reason == REASON_EXCEPTION_RST || rtc_info->reason == REASON_SOFT_WDT_RST)
{
os_printf("epc1=0x%08x, epc2=0x%08x, epc3=0x%08x, excvaddr=0x%08x, depc=0x%08x\n", rtc_info->epc1, rtc_info->epc2, rtc_info->epc3, rtc_info->excvaddr, rtc_info->depc);//debug garbled output.
halt();
}
Statistics: Posted by AgentSmithers — Thu Dec 09, 2021 4:42 pm