Agent code doesn't change when switching models

I’ve noticed that when changing the model running on an Imp the agent code doesn’t switch over to the new model’s agent code. The Imp device code gets loaded on the Imp and runs, but the agent code appears not to change. This leads to all sorts of problems if the models are quite different in terms of agent code.

In order to work around this problem, one must change a line in the agent code and save it, then cause the Imp and agent to start again.

Toby

This sounds like a major bug I hadn’t seen months ago. Can anyone verify? When will this be fixed?

There’s a lot happening there, this will be addressed fairly shortly.

After reading this I make a quick try and Agent code is change switching between models.

Thanks PeterAP - The problem I encountered may be a corner case related to the Imp not waking from sleep…

If the Imp is not online when you change models, and you cause the Imp to come online by removing it from the socket and reinserting it, the Imp downloads the new code, but the agent doesn’t change and stays on the one from the previous model.

@TheBarrelShifter I have make a try just in IDE - switch between codes for not online imp. I have “mechanically” make a code changes for imps online, offline and reinserting imp and haven’t recognise any strange “working” or not “working”. Inserting download new code and Agent, I suppose, change too - everything is working as expected. But I havent take a look directly on Agent code - it’s changing or not.
I’ll try some variants a bit later - question is very important for me too.

I have tested 3 live Models containing different Device code and Agent code for 1 imp.
In all cases Model changing for Device follow by code change in Agent as well as in Device. Everything works as designed.

Still experiencing this.
Try changing models whilst the Imp device is asleep. For me, the agent consistently doesn’t change to the new model.

Toby

@TheBarrelShifter is it possible to download new code when imp is sleeping? I don’t know, need to check. As I understand - to get work with new code it’s necessary to download it. Do you see in IDE that code doesn’t change or imp is just working without changes?

I’m not saying that the code changes whilst the Imp is asleep. The Imp awakes from sleep and downloads new code at that point, however the agent code that is running doesn’t change. You end up with device code from the new model running on the Imp, but agent code from the old model running on the server.

Toby

I’m not sure that awaking forces to download new code, at least I cannot find such information on documentation.

I didn’t find it in the documentation either, I’m just saying what I see.
It seems logical, though, that if the Imp cannot obtain new code whilst it’s asleep (which it can’t as the wi-fi is off), then it obtains new code when it wakes up.

Toby

@TheBarrelShifter, I make some tests and cannot find that awake forces to download new code. I change model in IDE and imp still work with pervious model, awaking or continuous running. Only pressing “Run” make change.

You can’t change running code without pushing “RUN”.
I would not like to have it otherwise (without explicit code to do so) :slight_smile:

Pushing “Run” will change the code straightaway if the imp is awake.

If the imp is asleep (or powered off), then what happens is, the first time it connects to the server after waking up again, it checks whether its code is now out-of-date (i.e. whether someone pushed “Run” while it was disconnected) and, if so, it downloads and runs the new code instead.

Peter

Hope we’ll ever get a function like imp.run(“some existing model”, x, y, z).
Then we can also forget our new function reboot() :slight_smile:

@DolfTraanberg, when it will be possible to apply reboot()?

NOW!
just ignore those two lines of red lines in your log :wink:

@DolfTraanberg, hmmm…red lines mess up “clear vision”. imp goes offline, then boot to online.
When red lines will disappear?
very necessary and good function, thanks!

no, it is the lack of the existence of that function that causes the reboot… :))