[Fixed/Solved] Calling a web PHP page not working anymore: after a code modification and flash

Hey friends! Here we go again! a perfectly working code for months, and then, need to modify my server ip address because I’ve move my web server and then nothing works anymore after flash… Simple script… From spark core, pin is put high, core connect to a webserver and runs a .php file that sends an email. If I use a laptop, or iphone and call the address it works, is spark core does it nothing works. This happens after a flash. If I take a working unit, reflash it with a mod, not working after.

It seems that everytime the code firmware is modify I have to start all over again my code. I’m arrived to the third version now on same board.

It would help if you could share the code, it’s hard to debug if we don’t know what we’re looking at.

how do we post a code again?

Like this would be nice:

Copy & Paste with the relevant syntax

1 Like
//

int millLast = 0;                    // Last time (in millis()) the doorbell was pressed
int b1 = D3;                // Button pin
int b2 = D4;
int b3 = D5;
int b4 = D6;
int millDelay = 5000;               // How much time to wait until we allow another doorbell "ring" again
char srvIP[] = "1.2.3.4";            // Server IP address
char srvHost[] = "myserver.com"; // HTTP 1.1 hostname
int srvPort = 80;                    // Server port number
char srvPath1[] = "b1.php";       // URL path
char srvPath2[] = "b2.php";       // URL path
char srvPath3[] = "b3.php";       // URL path
char srvPath4[] = "b4.php";       // URL path
int i=0;
int j=0;
int ledpower = 2;
int ledready = 7;
int beep1 = 0;
int ledState = LOW;             // ledState used to set the LED
long previousMillis = 0;        // will store last time LED was updated
// the follow variables is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long interval = 100;           // interval at which to blink (milliseconds)

TCPClient client;
void setup() {
    pinMode(b1, INPUT_PULLDOWN);
    pinMode(b2, INPUT_PULLDOWN);
    pinMode(b3, INPUT_PULLDOWN);
    pinMode(b4, INPUT_PULLDOWN);
    pinMode(ledpower, OUTPUT);
    pinMode(ledready, OUTPUT);
    pinMode(beep1, OUTPUT);
    RGB.control(true);
}
        
void loop() {
  digitalWrite(ledpower, HIGH);
  
    if(digitalRead(b1)==HIGH)
        bouton1();
    if(digitalRead(b2)==HIGH)
        bouton2();
    if(digitalRead(b3)==HIGH)
        bouton3();
    if(digitalRead(b4)==HIGH)
        bouton4();
    
    else
        RGB.color(255, 0, 0);
 
 
 if (Spark.connected()) {
digitalWrite(ledready, HIGH);
delay(75);
digitalWrite(ledready, LOW);
delay(75);
}
else
{
 digitalWrite(ledready, LOW);
}

unsigned long currentMillis = millis();
 
  if(currentMillis - previousMillis > interval) {
    // save the last time you blinked the LED 
    previousMillis = currentMillis;   

    // if the LED is off turn it on and vice-versa:
    if (ledState == LOW)
      ledState = HIGH;
      
    else
      ledState = LOW;

    // set the LED with the ledState of the variable:
    if (i<88){
    digitalWrite(beep1, ledState);
    i=i+1;
    }
    } 



}
void bouton1() {
    if(millLast==0 || (millLast+millDelay)<millis()) {
        millLast = millis();
        i=88;
        digitalWrite(beep1, HIGH);
        delay(200);
        digitalWrite(beep1, LOW);
        RGB.color(0, 255, 0);
        httpGetRequest(srvIP, srvHost, srvPort, srvPath1);
        RGB.color(0, 0, 255);
        delay(5000);
        digitalWrite(beep1, HIGH);
        delay(75);
        digitalWrite(beep1, LOW);
        delay(75);
        digitalWrite(beep1, HIGH);
        delay(75);
        digitalWrite(beep1, LOW);
        delay(75);
        digitalWrite(beep1, HIGH);
        delay(75);
        digitalWrite(beep1, LOW);
        
    }
}
 
 
void bouton2() {
    if(millLast==0 || (millLast+millDelay)<millis()) {
        millLast = millis();
        i=88;
        digitalWrite(beep1, HIGH);
         delay(200);
        digitalWrite(beep1, LOW);
        RGB.color(0, 255, 0);
        httpGetRequest(srvIP, srvHost, srvPort, srvPath2);
        RGB.color(0, 0, 255);
        delay(5000);
        digitalWrite(beep1, HIGH);
        delay(75);
        digitalWrite(beep1, LOW);
        delay(75);
        digitalWrite(beep1, HIGH);
        delay(75);
        digitalWrite(beep1, LOW);
        delay(75);
        digitalWrite(beep1, HIGH);
        delay(75);
        digitalWrite(beep1, LOW);
    }
}
 
 
void bouton3() {
    if(millLast==0 || (millLast+millDelay)<millis()) {
        millLast = millis();
        i=88;
        digitalWrite(beep1, HIGH);
         delay(200);
        digitalWrite(beep1, LOW);
        RGB.color(0, 255, 0);
        httpGetRequest(srvIP, srvHost, srvPort, srvPath3);
        RGB.color(0, 0, 255);
        delay(5000);
        digitalWrite(beep1, HIGH);
        delay(75);
        digitalWrite(beep1, LOW);
        delay(75);
        digitalWrite(beep1, HIGH);
        delay(75);
        digitalWrite(beep1, LOW);
        delay(75);
        digitalWrite(beep1, HIGH);
        delay(75);
        digitalWrite(beep1, LOW);
    }
}
 
 
void bouton4() {
    if(millLast==0 || (millLast+millDelay)<millis()) {
        millLast = millis();
        i=88;
        digitalWrite(beep1, HIGH);
         delay(200);
        digitalWrite(beep1, LOW);
        RGB.color(0, 255, 0);
        httpGetRequest(srvIP, srvHost, srvPort, srvPath4);
        RGB.color(0, 0, 255);
        delay(5000);
        digitalWrite(beep1, HIGH);
        delay(75);
        digitalWrite(beep1, LOW);
        delay(75);
        digitalWrite(beep1, HIGH);
        delay(75);
        digitalWrite(beep1, LOW);
        delay(75);
        digitalWrite(beep1, HIGH);
        delay(75);
        digitalWrite(beep1, LOW);
    }

}

 
void httpGetRequest(char* ip, char* hostname, int port, char* url) {
    char line[255];
    
    client.connect(ip, port);
 
    strcpy(line, "GET ");
    strcat(line, url);
    strcat(line, " HTTP/1.1");
    client.println(line);
    delay(100);
 
    strcpy(line, "Host: ");
    strcat(line, hostname);
    client.println(line);
    delay(100);
    
    strcpy(line, "Content-Length: 0");
    client.println(line);
    delay(100);
    
    client.println();
    delay(100);
    
    client.flush();
    delay(100);
    
    client.stop();
    delay(250);
}

Are there any specific 'symptoms'? does it work up until a certain part, does it flash red?

doesn't really indicate where the problem may lie, so any and all details you could give would be greatly benificial.

It behave exactlyliek when it was working, only the email do not come anymore. The b1.php page contains a sendmail function. This PHP page is working, when I run it from a computer or iphone browser, emails comes in. No error visible from the spark core board. I dont see the text exchange between the core and the web server.

Even my pushingbox code version is not working anymore on 3 different core… my 2 years old Arduino still works flawlessly…

I’m guessing that the dns resolving might be one of the reason why it’s failing…

There’s a test code somewhere so I’ll see if I can find it and update here!

What has changed in DNS resolving since august when I’ve put those core to work. Worked since then up to last flash?

The cc3000 dns resolver somehow behaves funny after code changes. It’s not really a software issue but some CC3000 related problem that we found out the hard way.

Can you try this: https://community.spark.io/t/problem-with-core-networking-and-dns-try-this-tool/7667

after applying the code as suggested, DNS is the f* colprit… 76.83.0.0. I’ve managed to set static ip with that code and then Factory default and flash my code and it works…

This is a problem… I need dhcp…

SSID : Antenne-1
Local IP : 10.0.10.125
Mac : 08:00:28:57:e0:d1
Subnet mask : 255.255.255.0
Gateway IP : 10.0.10.1
DNS IP : 76.83.0.0

1 Like

Can you try to do a CC3000 patch and see if the problem goes away?

DFU mode with the commands spark flash --usb cc3000 and spark flash --usb tinker once it’s done.

Just be sure to update Spark-cli if you haven’t done it in a while :slight_smile:

do i need do put in dfu mode and do i need dfu-util?

you can try doing the cc3k update a few times and it may clear, someone said it worked for them…

alternatively there is an alternate get host by name that i wrote that does the look-up for you, details here
its available as a library in the web IDE

2 Likes

@MartyMart, yup you need DFU-util but if you have Spark-cli previously, you should probably have dfu-util installed.

dfu-util -l on the command line should give you some output if it’s installed :wink:

trying to understand but not sure where this is going aka library… I need to add a library in my web ide code?

Used spark flash deviceid cc3000 form command prompt, worked and cleared faulty dns… back working with minor code change to fix intermittent connection. Move client.stop on http request from bottom to begining of routine and added a client.flush.

void httpGetRequest(char* ip, char* hostname, int port, char* url) {
    char line[255];
    
    client.stop();
    client.flush();
    client.connect(ip, port);
    strcpy(line, "GET ");
    strcat(line, url);
    strcat(line, " HTTP/1.1");
    client.println(line);
    delay(100);
 
    strcpy(line, "Host: ");
    strcat(line, hostname);
    client.println(line);
    delay(100);
    
    strcpy(line, "Content-Length: 0");
    client.println(line);
    delay(100);
    
    client.println();
    delay(100);
    
    client.flush();
    //delay(100);
    
    //client.stop();
    delay(250);
2 Likes

@MartyMart can we tag this as SOLVED then?

well… I’d say more fixed than solved… the problem is still possible to come again… But I understand what you mean and yes you could say Solved. Hope the DNS issue occuring for a lot of people will be adressed. Thanks to all of you out there for your help.

1 Like