Author Topic: Error : An error occurred while flashing the device:  (Read 17244 times)

exeng

  • Sr. Member
  • ****
  • Posts: 452
Re: Error : An error occurred while flashing the device:
« Reply #15 on: August 10, 2016, 07:46:36 pm »
OK, Still not able to do an OTA upload with Particle. So I did a serial upload of my very functional sketch that does Particle.publish, sends data to Thingspeak and is now again functional with Blynk (do to the 1.0.5 update). All works expect Particle stuff.

So for now I'll put this Oak back in service and pull out my last and only virgin Oak to see if I can get it operational doing the normal digistump instructions. We'll see how that goes.
Not going to touch and of my other Oaks until this is sorted.

kh, Did the serial output shed any light?

I'll post the result of trying to bring up a new Oak.

So in the worst case scenario I can serial load the OakSystem without debug and just resort to serial loads of my sketches... correct?

exeng

exeng

  • Sr. Member
  • ****
  • Posts: 452
Re: Error : An error occurred while flashing the device:
« Reply #16 on: August 10, 2016, 10:00:29 pm »
Since I have a repeatable failing OTA Oak, I'm wondering if further debug output from particle_core.cpp would help provide some clues? I'm tempted but really know where to start.

PeterF

  • Hero Member
  • *****
  • Posts: 883
Re: Error : An error occurred while flashing the device:
« Reply #17 on: August 10, 2016, 10:23:13 pm »
I don't profess to have any knowledge at all of what most of the output from the debug mode means, but for comparison, here is the output from has been a working Oak when re-flashed in debug mode as kh instructed. For easier side-by-side comparision of the two, have a look at the attached comparison report.

For the most part, they are essentially the same. They both seem to claim that they have successfully connected and hand-shaked. I suspect most the later differences are simply due to me leaving a bit more of the repeated (heartbeat related?) code in the snapshot. I power cycled it three times. I got the exact same output twice, but one time I got an "UPDATE ERROR; SHAKE LOOP FAIL; END AUTO CONNECT; NO CONNECT" message, and then it looks like it did the hand-shake again, so I presume it dropped the connection or had a momentary hissy fit, as it had already successfully handshaked. Anyway, here is the repeatable output from mine.

Code: [Select]
WIFI CONNECT
WIFI CONNECTED
PARTICLE CONNECT
AUTO CONNECT
START HANDSHAKE
SHAKE
4
BLRECV
40
SHAKE1
4
SHAKE2
BLSEND
256
0
SHAKE3
SHAKE4
BLRECV
SET KEY
SEND HELLO
GET HELLO RESPONSE
BLSEND
18
0
WAIT FOR SERVER HELLO
HRM1
BLRECV
HM1
0
Hanshake: completed
END HANDSHAKE
SEND EVENTS
BLSEND
50
0
BLSEND
50
0
SEND SUBS
BLSEND
18
0
BLSEND
18
0
SEND TIME REQ
BLSEND
0
5
LOOP
HRM1
BLRECV
HM1
13
HRM1
BLRECV
HM1
13
HRM1
BLRECV
HM1
13
HRM1
BLRECV
HM1
13
HRM1
BLRECV
HM1
1
BLSEND
244
5
BLSEND
34
0
END AUTO CONNECT
HRM1
BLRECV
HM1
12
BLSEND
50
0
BLSEND
50
0
AP ONLINE
START AP
STARTED
GOTO LOOP
HRM1
BLRECV
HM1
13
HRM1
BLRECV
HM1
8
HRM1
BLRECV
HM1
13
HRM1
BLRECV
HM1
8
BLSEND
18
0
HRM1
BLRECV
HM1
13
BLSEND
18
0
HRM1
BLRECV
HM1
13
BLSEND
18
0
HRM1
BLRECV
HM1
13
BLSEND
18
0
HRM1
BLRECV
HM1
13
BLSEND
18
0
HRM1
BLRECV
HM1
13
BLSEND
18
0
HRM1
BLRECV
HM1
13
BLSEND
18
0
HRM1
BLRECV
HM1
13
BLSEND
18
0
HRM1
BLRECV
HM1
13
BLSEND
18
0
HRM1
BLRECV
HM1
13

PeterF

  • Hero Member
  • *****
  • Posts: 883
Re: Error : An error occurred while flashing the device:
« Reply #18 on: August 10, 2016, 10:33:46 pm »
And from the same Oak, after commenting out #define OAK_SYSTEM_ROM_4F616B 82 and switching to OTA programming, this is what I got (it programmed and rebooted into the user rom without any issues.

I had to attach the output from the OTA programming as it was too long for a forum post.

I then get the following from the user rom program (my sketch) - basically that repeating (heartbeat?) output.

Code: [Select]
OakBoot v1 - N,BP,4

Sketch starting: Blink v0.3 <-- output from my sketch
BLSEND
50
0
HRM1
BLRECV
HM1
13
HRM1
BLRECV
HM1
8
BLSEND
18
0
HRM1
BLRECV
HM1
13
« Last Edit: August 10, 2016, 10:38:47 pm by PeterF »

kh

  • Jr. Member
  • **
  • Posts: 64
  • OakTerm developer
Re: Error : An error occurred while flashing the device:
« Reply #19 on: August 10, 2016, 10:49:28 pm »
kh, Did the serial output shed any light?

Sorry, I'm only getting a chance to look at this now. Nice job deciphering my instructions to get the serial debug log. It confirms that your Oak is handshaking with the Particle Cloud just fine. This is exactly the issue I had. The Particle Cloud is acknowledging the handshake, but for whatever reason, doesn't forward any events from the Oak or generate any system events for it (e.g. spark/status online).

This has proved a very difficult problem to debug because it only seems to affect the Oak (i.e. not any of the Particle devices - Core/Photon/Electron), and only a handful at a time. The Oak doesn't share the same firmware with the Core/Photon/Electron, so I suspect that either the Oak doesn't behave exactly to spec in it's interactions with the Particle Cloud, or the Cloud itself doesn't behave exactly to spec, in such a way that the Oak triggers some edge case bug that the Core/Photon/Electron don't.

More than likely, the problem will spontaneously resolve for you after some time (days to weeks - if you don't toss it out the window first :) ), as it has for all the other reported cases.


Since I have a repeatable failing OTA Oak, I'm wondering if further debug output from particle_core.cpp would help provide some clues?

It would definitely be helpful to post on the Particle forum so they're aware that this issue is still ongoing. See my post for links to the Particle forum threads discussing this, or feel free to create your own thread. I have supplied the Particle staff with similar serial debug logs from my Oak and corresponding packet captures, but since the problem spontaneously went away, I think they hoped it was fixed by the Oak 1.0.5 firmware changes.


exeng

  • Sr. Member
  • ****
  • Posts: 452
Re: Error : An error occurred while flashing the device:
« Reply #20 on: August 10, 2016, 11:07:26 pm »
Pete, Thanks. Never see any debug output that suggests firmware is being OTA loaded like in your attached file.

kh, Thanks for all the help. I would like to help get to the bottom of this. Still want to bring the new Oak up first to see what happens with the latest release and tool chain. After that, I may play with debug mods to particle_core to try and gain some insight as to what the issue may be with my failing Oak. At least it's back online sans Particle.

kh, you and Pete are light years ahead of me in understanding the Oak / Particle internals. Thank you both for that. I'm still skimming on the surface with the occasional deep dive but only when force to dive deeper. Glad you guys are around and contributing.

exeng

exeng

  • Sr. Member
  • ****
  • Posts: 452
Re: Error : An error occurred while flashing the device:
« Reply #21 on: August 11, 2016, 07:04:49 pm »
Created a custom version of OakCLI to try to get some additional info on why the flashing error. See the code fragment below...

Code: [Select]
  device.flash([onlyFile], function(err, data) {
            if (err || (data && data.ok == false)) {
              console.log('Error flashing: err=' + err + 'Data=' + data + 'DATA.OK=' + data.ok); // Debug
              errorAndQuit('An error occurred while flashing the device:');
As you can see I try to see what was coming back from Particle. At least I assume its a callback from Particle. I'm by no means fluent in .js so this was a brut force attempt.

What was returned for err was 'null' and 'false' for data.ok. Guessin the data.ok false is what caused the OTA upload bail. Unfortunately that's all I got because when I tried to add some additional debug to oak.js I got into a big fight with the build environment and eventually gave up as I'm also not well versed in the MS build tools / environment. Wanted to see the filename and path that was to be uploaded.

So with this little bit of info, does it shed any light on what may be happening between OakCLI and Particle?

kh

  • Jr. Member
  • **
  • Posts: 64
  • OakTerm developer
Re: Error : An error occurred while flashing the device:
« Reply #22 on: August 12, 2016, 09:16:03 am »
So with this little bit of info, does it shed any light on what may be happening between OakCLI and Particle?

Unfortunately, not much. The fact that err is null means that OakCLI got a response from the API call to the Particle Cloud, but ok=false says the Particle Cloud is telling us the flash was not successful. Did the data object have any other properties? From this post on the Particle forums, it looks like there should be a data.errors property with a more descriptive error message, but there's no documentation, so it's not clear whether data.errors is returned in every case.

exeng

  • Sr. Member
  • ****
  • Posts: 452
Re: Error : An error occurred while flashing the device:
« Reply #23 on: August 12, 2016, 09:39:56 am »
kh, Unfortunately I was only able to build the custom OakCLI once after installing node.js and Visual Studio C++ build tools and only sent err and data.ok to the console on the first version. Wasn't aware of other objects. When I tried to build again with some additional debug output I was getting an error when building...
 
Quote
error MSB4126: The specified solution configuration "Release|x86" is invalid.
The successful build must have added or changed something in the build environment which caused the next build to fail. Being a complete noob with the build environment, I spent hours trying to figure out why after the first build it complained about this and couldn't find a way to fix it. Out of frustration I gave up trying to build another custom OakCLI.

Thanks for the reference to the other objects. If I get the energy to try again (perhaps after figuring out how to fix the MSB3126) I'll try to output more info from OakCLI.

exeng

  • Sr. Member
  • ****
  • Posts: 452
Re: Error : An error occurred while flashing the device:
« Reply #24 on: August 12, 2016, 09:48:36 pm »
The saga continues...

Managed to get over the build issues with MSBuild environment (stupid bat file setting of Platform had to be changed to blank for whatever reason), but I digress.

Here is the OakCLI changes (fragment). My additions are the ones with // Debug comments:
Code: [Select]
          console.log('Sending file to cloud, to flash ' + config.devices[activeDeviceIndex].device_name + ' (Device ID: ' + config.devices[activeDeviceIndex].device_id + ')');
          console.log('Get ready to flash ' + onlyPath + onlyFile); // Debug
          device.flash([onlyFile], function(err, data) {
            if (err || (data && data.ok == false)) {
              console.log('Error flashing: err=' + err + 'DATA.OK=' + data.ok); // Debug
              console.log('Error flashing: CODE=' + data.code); // Debug
              console.log('Error flashing: ERRORS=' + data.errors); // Debug
              console.log('Error flashing: ID=' + data.id); // Debug
              console.log('Error flashing: STATUS=' + data.status); // Debug
              errorAndQuit('An error occurred while flashing the device:');

Anxious to try the OTA upload again on my failing Oak. For good measure I...
1. Did  Factory Reset
2. SoftAP firmware update
3. Using repo 1.0.5
Active on my router and claimed and connected to Particle.
http://192.168.1.70/device-id : {"id":"d9removed for public consumption","c":1}
http://192.168.1.70/system-version  : 10
http://192.168.1.70/version  : {"v":1}
http://192.168.1.70/particle :  Connected

Upload output:
Quote
Sketch uses 264,974 bytes (25%) of program storage space. Maximum is 1,040,368 bytes.
Global variables use 52,340 bytes (63%) of dynamic memory, leaving 29,580 bytes for local variables. Maximum is 81,920 bytes.
OakCLI tool version 1.0.2
Using config file at: C:\Users\Stephen\AppData\Roaming\oak\config.json
Sending file to cloud, to flash OAK_GD (Device ID: d9removed for public consumption)
Get ready to flash C:\Users\Stephen\AppData\Local\Temp\build8772214570984903817.tmpBlinkTestPgm.cpp.bin
Error flashing: err=nullDATA.OK=false
Error flashing: CODE=200
Error flashing: ERRORS=[object Object]
Error flashing: ID=undefined
Error flashing: STATUS=undefined

Error : An error occurred while flashing the device:
the selected serial port does not exist or your board is not connected

Since I don't know the structure data,I don't know if there is any other detail to be gained from ERRORS.

Don't understand where the final message is coming from and but it seems to think my board is not connected. Didn't see this message in OakCLI. I think the final message from OakCLI is the "An error occurred while flashing the device:" so the last bit may be just a generic message do the to failed upload. From where, who knows.

At least I can build custom OakCLIs. Any suggestions while this Oak continues to fail?

exeng

kh

  • Jr. Member
  • **
  • Posts: 64
  • OakTerm developer
Re: Error : An error occurred while flashing the device:
« Reply #25 on: August 12, 2016, 10:05:27 pm »
Since I don't know the structure data,I don't know if there is any other detail to be gained from ERRORS.

If you do "console.log(data.errors);", it should print the contents of that object. In fact, "console.log(data);" should hopefully dump the entire data object.

The difference here is with console.log("String" + object) you are converting the object to a string and then logging that string to the console, whereas with console.log(object), you are logging the object itself. The console.log function is smart and prints the contents of the object.

the selected serial port does not exist or your board is not connected

Not sure where this error is coming from. I suspect it may be from the Arduino IDE after OakCLI terminates. Perhaps there is something slightly different with your build options that makes it behave differently. I'm fairly confident this isn't related to your Particle Cloud problems as it happens after the flash failed.

exeng

  • Sr. Member
  • ****
  • Posts: 452
Re: Error : An error occurred while flashing the device:
« Reply #26 on: August 12, 2016, 10:20:40 pm »
kh, Thanks for the clarification. As I said .js is new for me. I come from the old days, hence the ex in exeng. Still have my well used copyright 1978 of Kernighan and Ritchie C Programming Language book. And that's not the start of it. Fortran, punch cards, time share, Pascal, PL1, Assembly, DOS, Basic on and Apple II used to control a stack sampling probe in a 60MW power plant in the late 70's, Unix internals, Networking firmware... I digress again.

Let me see if I can get more info.

exeng

exeng

  • Sr. Member
  • ****
  • Posts: 452
Re: Error : An error occurred while flashing the device:
« Reply #27 on: August 12, 2016, 10:58:10 pm »
Here is the latest after adding additional debug to OakCLI...

The changes again:
Code: [Select]
          console.log('Get ready to flash ' + onlyPath + onlyFile); // Debug
          device.flash([onlyFile], function(err, data) {
            if (err || (data && data.ok == false)) {
              console.log(data); // Debug
              console.log(data.errors) // Debug
              console.log('Error flashing: err=' + err + 'DATA.OK=' + data.ok); // Debug
              console.log('Error flashing: CODE=' + data.code); // Debug
              console.log('Error flashing: ERRORS=' + data.errors); // Debug
              console.log('Error flashing: ID=' + data.id); // Debug
              console.log('Error flashing: STATUS=' + data.status); // Debug
              errorAndQuit('An error occurred while flashing the device:');

The test sketch based on Pete's test blink sketch...
Code: [Select]
//defined back to front on the Oak
#define LED_BUILTIN BUILTIN_LED

// the setup function runs once when you press reset or power the board
void setup()
{
  Serial.begin(115200);
  Serial.println("Sketch starting: Blink v0.3");
  Particle.publish("oak/userrom/startup","Blink v0.3", 60, PRIVATE);
 
  // initialise digital pin 1 as an output.
  pinMode(LED_BUILTIN, OUTPUT);
}

// the loop function runs over and over again forever
void loop()
{
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  Serial.println("LED HIGH");
  delay(3000);                   // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(500);                   // wait for a second

The result...
Quote
Sketch uses 264,974 bytes (25%) of program storage space. Maximum is 1,040,368 bytes.
Global variables use 52,340 bytes (63%) of dynamic memory, leaving 29,580 bytes for local variables. Maximum is 81,920 bytes.
OakCLI tool version 1.0.2
Using config file at: C:\Users\Stephen\AppData\Roaming\oak\config.json
Sending file to cloud, to flash OAK_GD (Device ID: d9Removed for public consumption)
Get ready to flash C:\Users\Stephen\AppData\Local\Temp\build6816829742918824593.tmpBlinkTestPgm.cpp.bin
{ ok: false,
  code: 200,
  errors:
   [ { id: 'd9Removed for public consumption',
       status: 'Update failed - File was too big!' } ] }
[ { id: 'd9Removed for public consumption',
    status: 'Update failed - File was too big!' } ]
Error flashing: err=nullDATA.OK=false
Error flashing: CODE=200
Error flashing: ERRORS=[object Object]
Error flashing: ID=undefined
Error flashing: STATUS=undefined

Error : An error occurred while flashing the device:
the selected serial port
 does not exist or your board is not connected

Checked the size of BlinkTestPgm.cpp.bin and was reported as 259KB by file explorer. So why the file too big error?

exeng

kh

  • Jr. Member
  • **
  • Posts: 64
  • OakTerm developer
Re: Error : An error occurred while flashing the device:
« Reply #28 on: August 12, 2016, 11:44:54 pm »
Checked the size of BlinkTestPgm.cpp.bin and was reported as 259KB by file explorer. So why the file too big error?

The Oak reports its maximum ROM size to the Particle Cloud when it connects. I suspect this error results from the cloud getting this number wrong (probably zero) and comparing the size of the file to flash.

This is interesting. Before the fixes Erik added in 1.0.5, PeterF saw some strange behavior where his Oak would take a long time to connect, and when it finally did, the Particle Cloud would print out an unexpected event with the system description string the Oak sends on connection to the cloud (which includes the maximum ROM size). I wonder if there's still some issue here with the way the cloud is parsing this description string.

Let me try and draw Erik and the Particle folks attention to this and see if they can spot any issues. It might be a while, since they all seem to be very busy.

exeng

  • Sr. Member
  • ****
  • Posts: 452
Re: Error : An error occurred while flashing the device:
« Reply #29 on: August 12, 2016, 11:55:03 pm »
kh, Let me know if there is anything I can do to help.

exeng