How do I use a clock to update my UUID readings?

Greetings, Everyone

I feel as though I have come a long way but I am still being stymied by one thing. I started out trying to learn how to use TinyDB. Then, with virtual screens, I had to learn to replace TinyDB with basic text labels and text box readings. I still use TinyDB to store the Service UUID for instant recall.

"Everything works" except my UUID readings do not update. I have tried using a clock in many ways (except, perhaps, the correct way). I can achieve BLE data that updates with some clock placements but it usually comes at the expense of an error message until the BLE kicks in.

If someone with more knowledge than I on the matter would please tell me how to properly use a clock to achieve regular BLE updates, I would really appreciate it. I try to give myself a couple of days to work something out before I come begging for assistance and I have exceeded that self-imposed temporal restriction.

I have posted the entire block code, as I didn't know what to leave out to make it smaller. Thank you to anyone/everyone who can assist. I apologize that the code cannot be easily viewed without downloading it and using MS Paint, or some other image viewer.

(Canned Reply: ABG- Export & Upload .aia)
Export your .aia file and upload it here.

Thank you - Here it is . . .

Community_Review.aia (2.4 MB)

Allow me to add that I HAVE had success at getting the labels Temp_BLE, Humidity_BLE, and Pressure_BLE to update in real time with a clock but, in the best case, I receive an error message until the BLE connects. I think I simply want to use a clock at about a 2 second refresh rate to read the three UUID characteristics but I haven't found the right place from which to trigger it. There are also so many clock blocks that I cannot begin to decipher right now. A shortcut via some outside knowledge would be most satisfying at this point.

The app starts on the front page, calling up the NWS website and establishing a connection. One is offered a navigation page with mostly unpopulated buttons, and BLE is not considered until the ATMO button is clicked. Upon doing so, one is presented with a list from which to pick the proper device with the Scan button and the stop button is clicked when the device is present in the list. Highlighting the device selects it from the list and the Connect button takes you to the page showing the BLE outputs under three icons. Instead of the Scan/Stop/Connect procedure, one can click the Connect_Stored_Value button and pull up the service ID directly from TinyDB.

Regardless of how this is done, I wish to be able to update the three "_BLE" labels every few seconds, as they represent local real-time conditions. I am told that a clock is the way to do this but I am at a standstill.

I see you doing a one shot read of your various characteristics.

Please post your sketch, so we can see if it is periodically posting new readings, versus just posting new reading in response to incoming requests.

By the way, this is trouble:

Empty sockets are bad.

(A bad dentist)

You can drag this directly into your Blocks Editor workspace.

Reopening Screen1 is also bad for the memory stack height.

If you need to redo what happens in Screen1.Initialize, drag it out into a procedure (call it Initialize?) and call it from Screen1.Initialize and from that reset button click event.

Wow, there is a lot to chew on there. I feel as though you have my problem pegged and, if I may, I would like to ask a question that I have found no satisfying response for. In as few words as possible (we're at that "talk to me like a child" level;), Why would I even initialize a global list (benefits?) and what is the difference between a label that is included in the "make a list" block and a label left out entirely? Right now, I am going to act on that being a good thing and make a list of every label that contains data with no open blocks.

Thank you for all of this information. I will let you know what happens.

BLE_Sketch.ino (2.3 KB)

You included a loop in Screen1.Initialize where you blank out every Label in that list, presumably because you plan to show data in them later, and want them to start out empty? I don't know, that's YOUR code in Screen1.Initialize, right?
Leaving a Label out of that list would be right for a case where you are just using the Label as a prompt or header, and you need that text there for show.

To what purpose? Everything you code must have a purpose.

Correction . . . "Everything one [knowingly] codes must have a purpose."

If I understood more about lists, I would sure code better. I still don't know why I would make a list of labels vs. no list of labels. Won't a label perform exactly the same? At least for me where I have a limited number of data points.

Regardless, everything is working fine except I still don't know how to call up the UUID characteristics on a regular basis to refresh the screen output. This only has to happen with the BLE UUID readings, not the local NWS readings or the calculated readings. Depending on how I call the timer, I either receive no BLE data or I receive a runtime error upon opening the app because the BLE has not yet connected.

If you could tell me where to slip the Clock1.Timer into, or from where to trigger it, I would be most grateful and very relieved.

This code sequence in your .ino tells me you are sending those 3 values every 100 milliseconds:

   while (central.connected()) {
      // Read actual sensor values
      float temperature = bme.readTemperature();
      float humidity = bme.readHumidity();
      float pressure = bme.readPressure() / 100.0; // Convert Pa to hPa

      Serial.print("Temperature: ");
      Serial.println(" °C");

      Serial.print("Humidity: ");
      Serial.println(" %");

      Serial.print("Pressure: ");
      Serial.println(" hPa");



So in the AI2 app, all you need to do is after connection is established, do a BLE Register for floats, then the floats will arrive automatically without you having to do anything further than having those 3 BLE Event blocks that receive the floats.

You don't have to do any BLE Reads once you have Registered.
It's like a subscription.


Community_Review.aia (2.4 MB)

By the way, you don't need a Clock1 enable/disable if you don't have a Clock1.Timer event block. That is typically used for pre-BLE Bluetooth, which does not have a Register facility or an arrival event, and must poll periodically.

Thank you, thank you, thank you! It is too late for me to make much sense of this except that it is clear that you know exactly what is going on here and I hope to, as well, in the morning.

You still need to test.

Remember, I have no test setup.

Testing is my middle name. You have provided me with two new concepts. 1) clocks are not necessary for reading floats, and 2) BluetoothLE1.RegisterForFloats does what I thought BluetoothLE1.ReadFloats does.

That is the kind of priceless knowledge that I am unable to find in any instructionals. I wish someone would write an "MIT App Inventor for Dummies" book that addresses, in simple English (and not block operation) what each and every block does. The information I can find was written on a level that I cannot use and apply.

BTW, it is all now working as I had hoped with real-time changes occurring on the BLE display labels. Thank you, again, for sharing your knowledge and AI2 wisdom.

This information is not about AI2.

I found it searching the web for How Does BLE Work.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.