I have what will hopefully be a pretty simple question… I’d like to create a control widget that basically operates exactly like the standard “switch” widget, only instead of sending a 1 byte message as the current switch widget does (a “0” or “1”), I’d like to send my own text message. Looking at the examples online the closest I could find was “Example 2: Simple text box to set a variable” from the document “HTML Canvas Widget Examples”, though this appears to set a variable vs publish a value. Is there another example out there that publishes a value or is there a simpler approach you can point me to (such as the actual code for the switch widget)? Thanks!
Greetings, you may modify the example that you reference to send the value of the text box in the variable’s context, in that way you may store your custom string. The Json that you should build is as follows:
Thanks for the quick reply! Since I’d posted that initial query I’d found “Getting started” which (I think) clarified things a bit. I’m not really java knowledgeable (mostly c++) so I think if I understand correctly the java code in the example will update the variable which will automatically be sent to anyone that has subscribed to that variable. So, to first just be sure I understood that correctly I created the widget per the instructions on my dashboard, changing only the variable line to “var VARIABLE_ID = ‘CustomControl’;” and the token line to “var TOKEN = ‘BBFF-…’;” (with my login token). But I’m stuck on what I should be subscribing to in my client. Since the widget isn’t really connected specifically to any device I’m not sure what goes in the ??? space for device id → “/v1.6/devices/???/CustomControl/lv”. I’ve tried several things but I’m not getting messages delivered when I click the widget. If I can get the number messages delivered I can take a look at your suggestion and hopefully figure out how to get some text sent. Anyway, thanks again for your help!
Fantastic! Thanks again for the help. Pretty much straight away it works. Now I’ll mess with it to see if I can change the data from numeric to string. Thank you again!
Hmmm, after a few hours of messing with it I’m thinking maybe my initial question wasn’t clear. I found one of your other posts where you explained the changes to the html to accept text instead of numbers -
that worked, and then I tried many permutations of the line you gave me ({‘my-variable’: {‘value’: 1, ‘context’: {‘text’: ‘my-string’}}}) and eventually came up with the following line replacement in the javascript -
of all the permutations I tried this was the only one that would update the variable successfully. Looking at the data an example line reads -
DATE VALUE CONTEXT
2019-05-06 16:52:04 -07:00 1.00 {"text":"abc123"}
but after all that, no matter what I’ve tried, the payload that arrives at my client application only consists of the value string (i.e. “1”). Is that correct? I probably misunderstood but I thought the payload would include or be replaced by the context text? Anyway, again thanks for your help…
Hi there @ctbee , my apologies, it was my mistake in my last post. You should not use ‘lv’ at the end of the topic, lv means that you just wish to retrieve the last value of your variable. To retrieve the context, please use the topic below:
Thank you! No need to apologize, it’s probably documented somewhere and I just missed it. At any rate changing that worked straight away. So thanks…
I have a little IoT edge platform (www.omniot.com) that I’m developing that I’ve just added mqtt support to so users can send their sensor data to cloud platforms/dashboards without doing any coding. The mqtt support is not released yet but when I do (next few weeks) I’ll add a little tutorial on building out ubidots dashboards and publishing/visualizing data from our platform to yours. So anyway, again, thanks for your help!
Hi, oddly I logged out of my account and can’t log back in. It keeps letting me change my password but then won’t accept the new password (or what I’m pretty sure the original password was)…