ULB Recipes

I’m starting a new topic specifically on the ULB here. Xuguang.shao has already provided some very valuable information in another thread, but I think ULB is so powerful that it would be nice to have a thread that shows some specific fully working recipes. I find that all the examples provided so far are partial snippets, so some concrete examples would really help.

Would someone be able to for example post a working ULB that fires a custom event when the temperature and humidity sensor detects a temperature over 30 degrees? Or one that creates an event when the Ultrasonic Ranger sensor detects something closer than 1 meter?

A full example would make a great thing to study and work forward from.

Thanks in advance - the ULB option is really cool :slight_smile:

Hi bjarne, the ULB you talked about is what we call Iot system.Cool!

here is the attachment of the example project which can implement the ULB you said.Of course you need to code before it runs.Later you may see other ULB projects in the recipes, and you can try to make your own ULB for the recipes too! :slight_smile:

Any further question is welcomed to asked.
wiolink_servo.rar (2.65 MB)

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 :wink:

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.