Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 19:53 28 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Webmite (Picomite Web) mqtt statement

Author Message
gghh
Newbie

Joined: 07/03/2023
Location: United States
Posts: 13
Posted: 01:53am 13 May 2023
Copy link to clipboard 
Print this post

This "payload" accomplishes what I need to send to my mqtt broker or server.
I have not been able to accomplish this with much much trial and error.
Is it possible and how do I create this as a string to send in MMBASIC?

{"channel": "cabinm","resource": "tank","write": true,"data": 51}

Thank you.

By the way, I read the new topics every day.  I can't tell you how impressed I am with the brilliant work and kind, compassionate support that goes on here.
 
Turbo46

Guru

Joined: 24/12/2017
Location: Australia
Posts: 1611
Posted: 04:33am 13 May 2023
Copy link to clipboard 
Print this post

Without doing the whole lot. Is this the sort of thing you want?:
a$ ="{"+chr$(34)+"channel"+chr$(34)+","+chr$(34)+"resource"+chr$(34)+":"
print a$

Result:
  Quote  {"channel","resource":

The new /n codes may help you to shorten it (see the manual) but I don't use them and this was done in MMBascic for DOS.
To add more without making the line too long use:
a$=a$+blah blah blah


Bill
Keep safe. Live long and prosper.
 
gghh
Newbie

Joined: 07/03/2023
Location: United States
Posts: 13
Posted: 03:02pm 15 May 2023
Copy link to clipboard 
Print this post

Thank you Bill. That was the perfect suggestion.  I had been using all versions of escape characters (pg. 35 of the WebMite manual) and none worked.  But using Chr%(nn) codes did work and I could fashion the kind of string I wanted.

Hopefully this will help others in the future.  Also, one can define constants (or strings) similar to "Const q$=Chr$(34)" and "Const L$=Chr$(13)+Chr$(10)". This lets you use q$ and L$ for "double quotes" and CRLF.

Unfortunately, when I went back to the WEB MQTT PUBLISH command, I realized that it's format only allows one "topic" and "data value" pair to be sent.  If someone knows how to send several topic/value pairs together with MMBASIC, I would like to know how. It appears that a common format is a payload like

{"topic1": "value1", "topic2": "value2", "topic3": 51}

Thanks again Bill.
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3150
Posted: 04:15pm 15 May 2023
Copy link to clipboard 
Print this post

  gghh said  I had been using all versions of escape characters (pg. 35 of the WebMite manual) and none worked.


Had you entered "OPTION ESCAPE" at the start of the program (also on page 35)?
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
gghh
Newbie

Joined: 07/03/2023
Location: United States
Posts: 13
Posted: 04:38pm 15 May 2023
Copy link to clipboard 
Print this post

So I went back and tried more variations.  I had incorrectly been using the codes by not using them within quotes.  When used within quotes all forms work.

Printing the following: "\q"  "\&22"  "\034" all produce double quotes as does Chr$(34) without quotes.

So "operator error".  Thanks for your response.  

Do you have any insight into MMBASIC's mqtt commands?
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3150
Posted: 05:12pm 15 May 2023
Copy link to clipboard 
Print this post

  gghh said  Do you have any insight into MMBASIC's mqtt commands?


'Fraid not, sorry. I've tested mqtt using R-Pi-zero and PC, but it's been several years, and I don't remember anything.
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
gghh
Newbie

Joined: 07/03/2023
Location: United States
Posts: 13
Posted: 05:24pm 15 May 2023
Copy link to clipboard 
Print this post

Thanks again.  I'm sure if there is a way, it will show up here.  If not, no complaints. This is just a marvel as it is.
 
Turbo46

Guru

Joined: 24/12/2017
Location: Australia
Posts: 1611
Posted: 11:12pm 15 May 2023
Copy link to clipboard 
Print this post

I'm glad I was able to help a bit. I know nothing about mqtt, don't even know what it stands for and am not interested at the moment. Was afraid my answer would be rubbish in that context.

Bill
Keep safe. Live long and prosper.
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024