Newbie: spark core locks me out


#1

OK,
newbie here, i have had my spark core for several months now and was happy to get a few basic functions working, ie, i/o buttons LED outputs…
I gave up with the unit several months ago as it appeared i had “bricked” the device after uploading some code to it.
I did manage to restore the unit after all attempts of factory reset but the only thing that worked was connecting it to a PC and flashing some hardware reset from the PC via a USB link. Its that long ago i dont recall what i done but i know it was a pain in the a$$ to do and it now seems the same scenario has reoccured and for the hassle involved i’d quite happily toss the unit in the bin.
Following the factory reset (yellow flashes to white flashes LED) it sits there flashing blue awaiting the wifi credentials yet me ios app has no joy connecting (event though is did initially)
I fear i must revert back to the USB-PC resetting of the device which is more bother than i need right now and to be frank quicker to buy a new device, but a daft option if this is to happen again.
Is there another option?
Forgive my dumbness.

here’s the code the seemingly locked up my device:

// THIS CODE IS BAD IT LOCKS UP THE SPARK CORE
// DO NOT USE

// myurl is not the actual URL, as you may have guessed
char server[] = "www.myurl.co.uk";
char url[] = "/sparktestdir/?data=";
String somestring = "some_text_here";

int GreenLed = D0;
int RedLed = D1;
int YellowLed = D2;
TCPClient client;

void setup() {
    Serial.begin(9600);
    pinMode(GreenLed, OUTPUT);
    pinMode(RedLed, OUTPUT);
    pinMode(YellowLed, OUTPUT);
}

void loop() {
    somestring = "millis:" + millis();    
    
    Serial.println("Starting request");
    int retval = getrequest();
    Serial.print("Returns ");
    Serial.println(retval);
    delay(5000);
}

int getrequest(){
client.connect(server, 80);

if (client.connected()) {
        Serial.println("Connected to server.");
        client.print("GET ");
        client.print(url);
        client.print(somestring);        
        client.println(" HTTP/1.1");
        client.print("Host: ");
        client.println(server);
        client.println("Connection: close");
        client.println();

        unsigned int count = 0;
        unsigned long lastTime = millis();
        while( client.available()==0 && millis()-lastTime<10000) { //ten second timeout
          }  //do nothing
        lastTime = millis();
        while( client.available() && millis()-lastTime<10000 ) {  //ten seconds
          client.read();  //flush data
          count++;
        }
        client.flush();  //for safety

        //client.flush();
        delay(400);
        client.stop();
        Serial.print("sent and closed-bytes: ");
        Serial.println(count);
        
        digitalWrite(YellowLed, HIGH);    // Turn OFF the GreenLed pins
        delay(500); 
        digitalWrite(YellowLed, LOW);    // Turn OFF the GreenLed pins
        delay(100); 
        
    return 1;
     }
    else {
        client.flush();
        client.stop();
        Serial.println("Not connected");

        digitalWrite(RedLed, HIGH);    // Turn OFF the GreenLed pins
        delay(100); 
        digitalWrite(RedLed, LOW);    // Turn OFF the GreenLed pins
        delay(100); 
        digitalWrite(RedLed, HIGH);    // Turn OFF the GreenLed pins
        delay(100); 
        digitalWrite(RedLed, LOW);    // Turn OFF the GreenLed pins
        delay(100);     

        return 0;
    }
}

*I’ve edited your post to properly format the code. Please check out this post, so you know how to do this yourself in the future. Thanks in advance! ~@Moors7 *


#2

Have you tried running the device in safe-mode and then trying to flash it?


#3

Also get used to resetting it on the computer, it becomes super simple after a while! I share your sentiment when it comes to the frustration, but if you just learn how to use these suckers, they become entirely worthwhile


#4

If you’ve got the CLI installed, it should be fairly straight-forward to get your device back up and running. A tutorial on how to install that has just been released (for windows). You could also use this installer if you like (it allows you to select to install the CLI only)
Using that, you should be able to use particle setup to configure your device, while in listening mode. If that doesn’t work, there’s particle serial wifi. Alternatively, you could use a serial terminal (putty/coolterm) and press w (if I’m not mistaken).
I’m afraid the app for the Core has alway been a bit bothersome, but a USB connection isn’t too bad once you’re used to it. You end up using it quite a lot for debugging over Serial anyway (at least, I did).


@demented: although your vids are very educational, @slaphead is talking about the Spark/Particle Core, so I think neither video applies to his scenario. The Core hasn’t got Safe mode, and the setup process is different than the one for the Core. Nonetheless, keep up the work with the vids!


#5

I see. I kinda just post like I know what I’m talking about. I used to play a lot of Jazz, and the key is to fake it :wink:


#6

many thanks for the VERY quick replies, everyone.
Kinda reassuring to know that you say “get used to resetting it on the computer” @demented
so if this is how it is, at least i know, and i’ll spare some patience for it and a few deep breaths.
Thanks again everyone.

PS
any idea why that particular code cause it to freak out?


#7

It’s really not that bad. Admittedly, the Core is less user friendly than the Photon, but that’s to be expected. And with less user friendly I mean that it might take 10-15 seconds longer, that’s about it.
The Photon allows you to put it in safe mode, during which no (malfunctioning) user code runs, thus allowing you to wirelessly flash new (working) code. The Core doesn’t have that, but does have Factory Reset, which puts Tinker back on it but also erases credentials. That means you’ll have to reconfigure those, using either the app, the CLI or Serial. The alternative is that you flash you application over DFU mode (which is also a lot faster). That way, no new credentials have to be configured, and you can go straight from malfunctioning to functioning code :smile:

tl;dr, install the CLI with DFU-UTIL, it’ll make your life easier :smile:

What did (or didn’t) it do? Did it just ‘stop’, or did it show some fancy LED patterns?


#8

OK, so i’ve got a bit futher, however, my PC is unable to reset the wifi connection (as i’m sure it did before) to get me up and running. I get the prompt to connect to the core but the PC doesnt seem to “find” the core. Any advice, please. Again, apologies if i appear thick. thanks


#9

Is your device in Listening mode (I assume so)?
Alternatively, you could use a Serial program like Putty or coolterm. Connect the device in Listening mode, then press w and follow the steps shown.


#10

i assume with a blue light flashing its in listening mode, which it is


#11

another attempt. I managed to reflash the firmware using the DFU and zadig tools but i’m stuck there. Still not able to communicate with the device when connected to the PC.
Could anyone offer little more guidance- do i need to be in blue flashing mode or yellow flashing mode. And when in the right mode what do i need to do to establish the wifi connection so i can get back to “normal” runnings?
thanks to all that have helped.


#12

DFU mode is yellow flashing and to establish a wifi connection you need to be Listening mode (blinking blue).

In listening mode, does it show up as a COM port?


#13

yes, shows up as com port and i get the flashing blue LED

in DFU mode i can get my PC to go through the setup process and it appears to communication with the core. following entering the wifi credentials the CMD prompt says “wait until led is breathing cyan” then "Claiming your core"
but all i get then is the flashing green led which i understand means wifi communication failure. I’ve tried WPA WEP and even disabled wifi security. the same regarding passwords. but flashing green led is where i’m hitting a brick wall. I wonder if the wifi components have been damaged?
thanks again


#14

i managed to solve my spark frustration this evening.
I’ve saved myself further hours of torment with the support from a large hammer.
i am now confident it has an irreparable fault. happy days!