SIM 800L and MQTT component

Use this section to discuss your embedded Flowcode projects.
Post Reply
george_b
Posts: 18
http://meble-kuchenne.info.pl
Joined: Fri Jul 01, 2022 5:00 pm
Has thanked: 9 times
Been thanked: 2 times

SIM 800L and MQTT component

Post by george_b »

Hi!

I am using Flowcode 9 and trying to implement a project using MQTT component.
Combining the MQTT component and the Network Communication component, i managed to run a simple program successfully.
I am able to publish and receive data from the broker properly.
What i want to achieve is to use a GSM module (such as SIM 800L) and MQTT component.

Is it possible to implement this in flowcode 9 ?


Thanks in advance
George

george_b
Posts: 18
Joined: Fri Jul 01, 2022 5:00 pm
Has thanked: 9 times
Been thanked: 2 times

Re: SIM 800L and MQTT component

Post by george_b »

in MQTT Client properties i spotted that in the Network Component field i can select also GSM.

Would this be the solution to my question above?

chipfryer27
Valued Contributor
Posts: 1135
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 281 times
Been thanked: 410 times

Re: SIM 800L and MQTT component

Post by chipfryer27 »

Hi

I've recently been playing with the MQTT component, but not yet having much luck.

To use the GSM to send data requires a little bit of configuration as off the bat the SIM800 doesn't do an awful lot. I think perhaps you would first need to establish a GPRS connection before you went any further. This is easily done by sending "AT Commands".

May I ask what broker you managed to connect to using the MQTT component? I looked at connecting to ThingSpeak, following their MQTT guide but that didn't work. I suspect that the problem is with the component in that it only allows 20 characters for each user-credential and ThingSpeak is providing ID's / username / passwords in excess of that.

If you want I'll send you an example of connecting to GPRS using the SIM800 or you can have a look at my recent posts in the v8 forum.

Regards

george_b
Posts: 18
Joined: Fri Jul 01, 2022 5:00 pm
Has thanked: 9 times
Been thanked: 2 times

Re: SIM 800L and MQTT component

Post by george_b »

chipfryer27 wrote:
Tue Jul 12, 2022 8:37 pm
Hi

I've recently been playing with the MQTT component, but not yet having much luck.

To use the GSM to send data requires a little bit of configuration as off the bat the SIM800 doesn't do an awful lot. I think perhaps you would first need to establish a GPRS connection before you went any further. This is easily done by sending "AT Commands".

May I ask what broker you managed to connect to using the MQTT component? I looked at connecting to ThingSpeak, following their MQTT guide but that didn't work. I suspect that the problem is with the component in that it only allows 20 characters for each user-credential and ThingSpeak is providing ID's / username / passwords in excess of that.

If you want I'll send you an example of connecting to GPRS using the SIM800 or you can have a look at my recent posts in the v8 forum.

Regards
Hi, thank you for your reply.


well, i managed to communicate with the broker using the MQTT component in simulation mode. I didn't uploaded the firmware onto the MCU yet but in simulation it is working fine.

The broker i am using is PUBNUB and i use the MQTT bridge to publish and subscribe to a topic.

Note that if you want to use the MQTT component you should also use the NetworkCommunications component to gain connection with internet and therefore with your broker.

So, drop both MQTT and NetworkCommunications component in the dashboard panel and go to MQTT component properties,
Now select "Network Comms" in the Network Component field. Thats it, try to simulate your program and it should work fine.


The Client identifier maximum length of 20 characters makes no sense to me.
Personally, i typed a string of 92 characters in this field in order to achieve communication with the broker (client_id=publish_key + "/" + subscribe_key + "/" + client_id)).
As i said the program works fine during simulation, maybe won't work if i upload it on hardware due to the character limitations!?




I really want to use the sim800L to send and receive data from/to broker.
Any help will be much more appreciated.


Regards
George

chipfryer27
Valued Contributor
Posts: 1135
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 281 times
Been thanked: 410 times

Re: SIM 800L and MQTT component

Post by chipfryer27 »

Hi

I managed to connect using the MQTT component last night. I'm using ThingSpeak and it automatically created a MQTT device for me when I created my channel(s). I've no idea why, but this wouldn't work using the supplied credentials. When I created another MQTT Device from within TS and used these new credentials I could connect without issue.

Whilst testing I used an ESP32 as it can simply hang off the end of my laptop to confirm all works in HW as well as in simulation. All good, mainly, but I have only the most basic setup, not even checking if I am connected to WiFi etc so I'm putting any issues down to the skeletal structure.

Leigh (Matrix) kindly confirmed that the Client Identifier field in the component is indeed greater than 20 characters (32) so the "tool tip" was a bit misleading suggesting a limit of 20.

Whilst messing with the SIM800 to update ThingSpeak using an API key and to also send Texts, I noticed a few issues when using the FC GSM component so I resorted to using "AT" commands sent from the UART RS232 component. Although I've not tested, as I've just got the MQTT to update over WiFi, I think you will need to configure the SIM800 along the following

Check to see if you are registered on the Network
Check to see if you are attached to GPRS
Start up IP connection
Set your APN (access point name, get this from your service provider)
Bring up wireless connection
Get IP address

From here you might be able to start using the MQTT/Network components. I have an example of the above on the v8 forum, but I intend to try and update to using the MQTT component too. Please note the v8 forum example was just for testing, checking each step as I went and can be easily improved.

Regards

chipfryer27
Valued Contributor
Posts: 1135
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 281 times
Been thanked: 410 times

Re: SIM 800L and MQTT component

Post by chipfryer27 »

Hi

I knocked up some code last night that will hopefully connect via GSM and update ThingSpeak using the MQTT component. Won't be able to try it out until the weekend due to poor coverage.

Regards

george_b
Posts: 18
Joined: Fri Jul 01, 2022 5:00 pm
Has thanked: 9 times
Been thanked: 2 times

Re: SIM 800L and MQTT component

Post by george_b »

Hi

if you have any new please let me know. I am really interesting on this.

Regards
George

chipfryer27
Valued Contributor
Posts: 1135
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 281 times
Been thanked: 410 times

Re: SIM 800L and MQTT component

Post by chipfryer27 »

Hi

I didn't notice at the time but the Network Component doesn't support connection to the GSM component therefore as things stand you cannot use the MQTT to update via the GSM component.

As ThingSpeak allows updates using "GET" and API Keys I don't have much need for the MQTT component itself. However there may be MQTT servers that don't allow these requests so I thought I'd try and capture what the MQTT component gets up to so that I could perhaps use the UART to mimic via the GSM component.

The Network Component does support the ESP8266. I can already update ThingSpeak via ESP/GSM using the UART and sending strings based on API Keys. I then captured the transmissions between chip and ESP using the MQTT component to see what is being sent and in what format as this would be quite different to using the API Keys.

I created a simple chart that would connect to my WiFi and hopefully update ThingSpeak. After a bit of tweaking I could update and captured the Tx and Rx transmissions. However the ASCII is quite funky in that it contains many "hieroglyphics" and the resulting Tx text file created omits the last line displayed on the screen which is no doubt to do with what is being captured. I did take a screenshot too which shows the characters as I see them. I then captured in Hex. Anyone fancy translating? Thought not...:) (opening up the created file in Notepad++ does show "control" characters, but unfortunately the last line isn't captured to file).

Not being bored enough on this wet morning I replaced the MQTT component used in the above with the IOT Made Easy component. Same code just the component change. This didn't work too well. From monitoring transmissions (I'm back in ASCII coz I'm not thaaaat bored to read in Hex) I could see that all was going well until it came time to send my "Topic" and "Payload".

When using the MQTT component, you can assign variables to contain the relevant string of characters for the Topic and Payload, meaning you can change fields quite easily (e.g. topic = "channels/123456/publish/fields/field1"). The IOT component does not allow the use of variables and you need to set the Topic string in the component itself (e.g. channels/123456/publish/fields/field1). Note that you don't put your string inside quotation marks. A seperate "Topic" is required per field you wish to update, identified by a byte in the command icon.

Once I'd figured that out I could update ThingSpeak and again captured the transmissions with similar results to the above.

If I get time later I might look at now re-creating the string(s) to send via the UART that would update a MQTT server, but it would be a lot easier if the Network Component was upgraded to work with the GSM. Is it too early to write to Santa? :)

Regards

BenR
Matrix Staff
Posts: 1726
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 438 times
Been thanked: 602 times

Re: SIM 800L and MQTT component

Post by BenR »

Hello,

Sounds like there's good progress going on here. Thanks for keeping us informed.

As for changing the network comms to work with GSM, yes this is probably possible but maybe tricky to do in a generic way as I think different GSM modules may do GPRS comms in different ways using different AT commands.

The Network comms component really just needs to do the following things so if we can find a way of doing each of these via GPRS then it should be fairly simple.

SocketOpen / SocketClose - Open and close a local socket to do comunications via
Connect - Connect to an IP as a client
Send / Receive - Generic send and receive data

Also these for server side things, e.g. WebServer or Modbus TCP Slave

Listen - Bind a socket to a port and listen for incoming data
AcceptOpen / AcceptClose - Opens and closes the ability to accept incoming messages e.g. HTTP servers, open detects when there is a client connected

chipfryer27
Valued Contributor
Posts: 1135
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 281 times
Been thanked: 410 times

Re: SIM 800L and MQTT component

Post by chipfryer27 »

Hi Ben

That's why I asked if it was too early to write to Santa :)

Thanks for detailing what the Network components gets up to and I believe the 800 can also do this, but I need to check as it was a few weeks since I last read up on it.

I will revisit once I get a bit of time.

Regards

Post Reply