Xinyuan-LilyGO / LilyGo-T-SIM7080G

42 stars 22 forks source link

MQTT Publish Issues #8

Closed bootcampiot closed 1 year ago

bootcampiot commented 1 year ago

Hi,

I found ModemMqttPulishExample the snprintf format below was not aligned with the parameters definition of SMPUB in SIMCOM MQTT application documentation, username, clientID and data_channel are not required here.

// AT+SMPUB=<topic>,<content length>,<qos>,<retain><CR>message is enteredQuit edit mode if messagel ength equals to <contentlength>
snprintf(buffer, 1024, "+SMPUB=\"v1/%s/things/%s/data/%d\",%d,1,1", username, clientID, data_channel, payload.length());

I am trying to construct below SMPUB to publish topic "device_connect" to AWS IOT Core, but saw "ERROR" response and no data arrived at AWS IOT Core.

snprintf(buffer, 1024, "+SMPUB=\"%s\",%d,1,1", pub_topic.c_str(), payload_rtcMem.length()); (output is AT+SMPUB="$aws/things/xxxxxxxxx/event_type/device_connect",339,1,1) modem.sendAT(buffer); modem.stream.write(payload_rtcMem.c_str(), payload_rtcMem.length());

{payload}

ERROR

wenjun1972 commented 1 year ago

Hi, Lewis,

Please advise about this issue.

Thanks,

Jun

lewisxhe commented 1 year ago

Please note that the topic published by the SMPUB command needs to be surrounded by double quotes. You should change it to the following

snprintf(buffer, 1024, "+SMPUB=\"%s\",%d,1,1", pub_topic.c_str(), payload_rtcMem.length());
wenjun1972 commented 1 year ago

The missed "\" was the issue from github comment writing, it was stripped out in my issue report text, very strange here. Both of my publish and subscribe didn't work, no message arrive at AWS IOT Core, only the presence of device connect and disconnect.

My publish shows as below

snprintf(buffer, 1024, "+SMPUB=\"%s\",%d,1,1", pub_topic.c_str(), payload_rtcMem.length());

My subscribe shows as below

snprintf(buffer, 1024, "+SMSUB=\"%s\",1", sub_topic.c_str())

lewisxhe commented 1 year ago

Subscribe and publish commands are valid if you fill in the parameters according to the manual, at least I have tried it, and you can use a free public MQTT server to test https://www.emqx.com/zh/mqtt/public-mqtt5-broker

wenjun1972 commented 1 year ago

I had a try over the weekend, this pub and sub format worked well on cayance.mydevice.com, test.mosquitto.com, but never success at AWS IOT Core, I guess this format only works on the MQTT basic authentication approach by username, password and clientID.

lewisxhe commented 1 year ago

No, since the connection is successful, it is definitely possible. So far, I haven't had time to try, there are too many things to do. If you have any news, please let me know

lewisxhe commented 1 year ago

Any progress?

wenjun1972 commented 1 year ago

We tried with huge effort but failed to make MQTT publish working with AWS, now we change to other SIM platform and applied UDP approach which is good to our use case. Did you have any test done for MQTT publish with AWS ?

lewisxhe commented 1 year ago

Sorry, I haven't completed it yet. I am currently contacting technical support from Simcom. I will update you promptly if there is any news

junwenatsmartguard commented 1 year ago

Hi, Lewis,

We made good progress today, MQTT published messages were well received at AWS core.

The changes we made were to change qos from 1 to 0 and retain from 1 to 0 in ----> AT+SMPUB=\"%s\",%d,0,0", pub_topic.c_str(), pub_payload.length()

We can close this issue now.

lewisxhe commented 1 year ago

Good news! If the test is successful, please submit a PR.

bootcampiot commented 1 year ago

Will submit PR this week.

wenjun1972 commented 1 year ago

Hi, Lewis,

I just submitted 3 PRs, please check.

Regards,

Jun

From: Lewis He @.> Date: Saturday, May 27, 2023 at 12:19 AM To: Xinyuan-LilyGO/LilyGo-T-SIM7080G @.> Cc: Jun Wen @.>, Comment @.> Subject: Re: [Xinyuan-LilyGO/LilyGo-T-SIM7080G] MQTT Publish Issues (Issue #8)

Good news! If the test is successful, please submit a PR.

— Reply to this email directly, view it on GitHubhttps://github.com/Xinyuan-LilyGO/LilyGo-T-SIM7080G/issues/8#issuecomment-1565248922, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ACJN5SQK2WETADO4FDYQOP3XIGTJLANCNFSM6AAAAAAW37YITQ. You are receiving this because you commented.Message ID: @.***>