Project

General

Profile

Ethercard browseUrl only works on first call

Added by DaveOB about 4 years ago

Ethercard browseUrl only works on first call

Symptom — I am using a loop to read data from an SD card file ( 1 line at a time ), and then upload the data to an online php script.
So far, so good.

In the code, I have also set a timeout of 10 seconds, so that I do not get stuck waiting for the callback if there is a network / internet / server problem.

The php script is receiving the GET data from the first browseUrl and saving it to an online txt file.

The code waits for the callback to match an MD2 has that is returned by the php script ( compares to an MD2 of the data sent to the php ) and if this is found ( before the timeout ), then the loop repeats for the next line of data in the SD card file.

This is where it fails.

The Serial monitor shows me the first browseUrl working 100%, the callback activates, the MD2 hash is confirmed, and the second loop starts.

In the second loop, the code gets to the browseUrl line, but the callback is NEVER activated, and the online php script NEVER receives the GET data.

The callback function STARTS with : Serial.println(F("my_callback function"));
so I am reasonably certain that it is never called, and the fact that the online php script does not get the data, that the browseUrl command is where the fault starts.

I suspect that something is not being re-set or ‘closed off’ at the end of the first browseUrl ?

If I ADD the line @ initEthernet();@ in the loop, before the packetLoop, persistTcpConnection and function that calls the browseUrl, makes it work 100% as expected.

So to avoid having to reset the ethercard before every data upload loop, what do I need to reset / change ?

My ethercard setup function ( called in the setup() ) looks like this :

    void initEthernet(){
        if (ether.begin(sizeof Ethernet::buffer, mymac, 46) == 0){
            if(DoDebug == 1) Serial.println(F("Failed to access Ethernet controller"));
        }else{
            ether.staticSetup(static_ip,static_gw,static_dns);
            if(DoDebug == 1) Serial.println(F("Ethercard Started"));
        }
        ether.printIp("IP:  ", ether.myip);
        ether.printIp("GW:  ", ether.gwip);  
        ether.printIp("DNS: ", ether.dnsip);  

        if (!ether.dnsLookup(website)) if(DoDebug == 1) Serial.println(F("DNS failed"));

        if(DoDebug == 1) ether.printIp("SRV: ", ether.hisip);
        if(DoDebug == 1) Serial.println(F("initEthernet function completed"));

    }    // end of : void initEthernet

In my main loop, I am using :

//  initEthernet();  // adding this line here to reset the ethercard makes it work 100% as expected.
    ether.packetLoop(ether.packetReceive());
    ether.persistTcpConnection(true);
    UploadResults();

and the function :

    void UploadResults(){
        if(DoDebug == 1) Serial.println(F("UploadResults function"));

        ether.browseUrl(PSTR("/inc/abc.php?xx1="), TXbufRES, website, my_callback);

        if(DoDebug == 1) Serial.println(F("UploadResults function completed"));
    }