Thanks sheepjms, I really appreciate the response and browsing through your project made some sense (although it didn’t really address the ULB as far as I could tell). Mind you, I’m a Java guy, so I don’t even have a C++ development environment. I’m simply coding the ULB in text only, taking extreme care not to mess it up
With the ULB, you insert new firmware code between the initial firmware generation and the actual firmware being run. I’ve only had today to play with it due to other work commitments, but so far I’m finding it incredibly handy. I’ve gone ahead and tried to figure out my first case in the above post myself and I just succeeded.
So as an example recipe for this thread, the following is a ULB for a Wio board that has a button and a Temperature & Humidity sensor attached. It checks every half second if the temperature has changed from previous reported values. If it has, a new web socket event will be generated. This is MUCH better than polling the sensor.
{"./Main.h": "#ifndef __MAIN_H__\r\n#define __MAIN_H__\r\n#include \"suli2.h\"\r\n#include \"grove_temp_hum_gen.h\"\r\n#include \"grove_button_gen.h\"\r\n\r\nextern GroveTempHum *GroveTempHumD0_ins;\r\nextern GroveButton *GroveButtonD2_ins;\r\n#endif\r\n", "./Main.cpp": "#include \"wio.h\"\n#include \"suli2.h\"\n#include \"Main.h\"\n\nuint32_t time;\nfloat tempPast;\nfloat tempNow;\nvoid setup()\n{time = millis();\ntempPast = 3000;\n}\n\nvoid loop()\n{if (millis() - time > 500){time = millis(); GroveTempHumD0_ins-> read_temperature(&tempNow); if (tempNow!=tempPast) { tempPast = tempNow; wio.postEvent(\"new_temperature\", tempNow); }}\n\n}\n"}
To install this ULB, I first used the mobile app to create an initial working firmware and I downloaded the basic un-modified ULB from the Wio board using a GET to iot.seeed.cc/v1/cotf/project, alongside my access token.
That gave me some skeleton code, including the declaration of the sensor instances.
So after reading through the API documentation I used a POST command to send the above modified code to iot.seeed.cc/v1/cotf/project, alongside my access token and a content type of “application/json”.
Once that was done, I forced the Wio board to load the ULB by performing a POST command to iot.seeed.cc/v1/ota/trigger with my access code and the parameter build_phase set to 2.
With that done, a short restart period took place and I now get events every time the temperature changes and every time the button is pressed.
The output from my WebSockets monitor looks like this:
2016-05-18 14:16:58.036::{"msg": {"new_temperature": "22.00"}}
2016-05-18 14:17:01.147::{"msg": {"new_temperature": "23.00"}}
2016-05-18 14:17:02.029::{"msg": {"new_temperature": "22.00"}}
2016-05-18 14:17:04.073::{"msg": {"new_temperature": "23.00"}}
2016-05-18 14:17:04.375::{"msg": {"button_pressed": "13"}}
2016-05-18 14:17:06.015::{"msg": {"new_temperature": "24.00"}}
2016-05-18 14:17:08.947::{"msg": {"new_temperature": "23.00"}}
The only major issue I have found so far is that there isn’t an easy way to “clear” the ULB when you change sensors. As far as I can tell, you literally have to upload the skeleton code gain to clear things out.