Hello Dasha,
I’m not using a library. After everything is initialiezed i just have this “switch case” which goes to the next step when the button is pressed.
The AT commands are from the quectel bc660k-gl mqtt notes.
switch(button_counter)
{
//disable sleepmode
case 1:
printf("AT+QSCLK\r\n");
quectel_send("AT+QSCLK=0",QUECTEL_BLOCKING);
err=quectel_get_response(QUECTEL_TIMEOUT_5S);
buf=quectel_get_recbuf();
printf("\r\nStatus %i\r\n%s\r\n",err, buf);
once=0;
break;
//put ca cert to quectel
case 2:
printf("AT+QSSLCFG\r\n");
quectel_send("AT+QSSLCFG=0,0,\"cacert\"",QUECTEL_BLOCKING);
err=quectel_get_response(QUECTEL_TIMEOUT_5S);
buf=quectel_get_recbuf();
printf("\r\nStatus %i\r\n%s\r\n",err, buf);
err=quectel_get_unsolicited(QUECTEL_WAIT,2000);
for (int p=0;p<strlen(cert);p++)
{
uart2_putc(cert[p]);
}
uart2_putc('\032');
err=quectel_get_response(QUECTEL_TIMEOUT_5S);
buf=quectel_get_recbuf();
printf("\r\nStatus %i\r\n%s\r\n",err, buf);
once=0;
break;
// enable ssl
case 3:
printf("AT+QMTCFG=\"ssl\"");
quectel_send("AT+QMTCFG=\"ssl\",0,1,0,0",QUECTEL_BLOCKING);
err=quectel_get_response(QUECTEL_TIMEOUT_5S);
buf=quectel_get_recbuf();
printf("\r\nStatus %i\r\n%s\r\n",err, buf);
once=0;
break;
//set mqtt version to 3.1.1
case 4:
printf("AT+QMTCFG=\"version\"");
quectel_send("AT+QMTCFG=\"version\",0,1",QUECTEL_BLOCKING);
err=quectel_get_response(QUECTEL_TIMEOUT_5S);
buf=quectel_get_recbuf();
printf("\r\nStatus %i\r\n%s\r\n",err, buf);
once=0;
break;
//open hivemq cloud
case 5:
printf("AT+QMTOPEN");
quectel_send("AT+QMTOPEN=0,\"7da17e617ce348f0844f3e2df7bec2d0.s2.eu.hivemq.cloud\",8883",QUECTEL_BLOCKING);
err=quectel_get_response(QUECTEL_TIMEOUT_5S);
buf=quectel_get_recbuf();
printf("\r\nStatus %i\r\n%s\r\n",err, buf);
err=quectel_get_unsolicited(QUECTEL_WAIT,15000);
printf("\r\nStatus %s\r\n", buf);
once=0;
break;
//connect with hiveMq broker
case 6:
printf("AT+QMTCONN");
quectel_send("AT+QMTCONN=0,\"xxx\",\"xxx\",\"xxx\"",QUECTEL_BLOCKING);
err=quectel_get_response(QUECTEL_TIMEOUT_1S);
buf=quectel_get_recbuf();
printf("\r\nStatus %i\r\n%s\r\n",err, buf);
err=quectel_get_unsolicited(QUECTEL_WAIT,15000);
printf("\r\nStatus %s\r\n", buf);
once=0;
break;
//publish test message
case 7:
printf("AT+QMTPUB");
quectel_send("AT+QMTPUB=3,0,0,0,\"test/topic\",5,\"test\"",QUECTEL_BLOCKING);
err=quectel_get_response(QUECTEL_TIMEOUT_5S);
buf=quectel_get_recbuf();
printf("\r\nStatus %i\r\n%s\r\n",err, buf);
once=0;
break;
default: break;
}
answer to AT+QMTOPEN: +QMTOPEN: 0,0 (succesful)
answer to AT+QMTCONN: +QMTCONN: 0,0,5 (sent packet successfully and received an ACK from server, Connection refused: Unauthorized)
and of course when i try to publish something after that message i get an error…
what could be the problem with my password and username?
I just wrote them into the “xxx” fields as i wrote them in the access manager.
Thank you and Best Regards
Felix