Home » Language IDEs » C / C++ IDE (CDT) » Can't configure user to mqtt broker using C funtions(Programming auto connect to user)
Can't configure user to mqtt broker using C funtions [message #1836287] |
Mon, 28 December 2020 11:31 |
leon chen Messages: 1 Registered: December 2020 |
Junior Member |
|
|
Hi all,
I have an issue with setting the MQTT User Configuration using the Basys MX3 in combination with an ESP32 wifi module
Everytime when I try to run my program it shows this message as error
the errorcode is 0x010a6002 and from what I found on this site
esspressif.com
it means that it is not in a configured state. The strange thing is when I try to manually type in the configuration in teraterm I get don't get this problem and I can connect just fine to the broker. This is the broker I am using right now mqtt.eclipseprojects.io/mqtt. I am kind of stuck for a few days now and I couldn't really find a concrete solution for this. I would like some help with it.
This is the set-up us when typing manually:
And I use teraterm to type in the AT commands
This is the set-up when trying to run the programm automatically:
It connects to the network protocol just fine, but when executing the function to set usercfg I get the errorcode you see in the first png.
This is the code I use to run the whole programm:
#include <xc.h>
#include <stdio.h>
#include <string.h>
#include "./mcc_generated_files/mcc.h"
#include "ESP32.h"
#include "uart.h"
#include "lcd.h"
#define Baudrate 115200 //baudrate in which data needs to be sent to esp32
void alternateLEDS();
void blinkLEDS();
void blinkLED(int ledNum);
// for connection with wifi
char conectionName[] = "Synology";
char password[] = "Keizergarden1994/";
//for serverconnection
char ntpServer[] = "0.nl.pool.ntp.org";
unsigned int enable = 1, timezone = 2;
//MQTT userconnection information
unsigned int linkID = 0 , scheme = 7, cert_key_ID = 0, CA_ID = 0;
char ClientId[] = "ZYBOESP32";
char username[] = "Jeedella";
char MQTTpassword[] = "Jeedella";
char path[] = "wss";
//connections to broker
char host[] = "mqtt.eclipseprojects.io/mqtt";
unsigned int reconnect = 1, port = 443;
//subscribe and publish
char topic[] = "hello";
char topic2[] = "hello_2";
unsigned int qos = 1;
char data[] = "I am here";
char retain = 0;
//const char dummy_sens_data[] = "25volts"; //dummy data from a sensor
//char macAdress[] = {0x30, 0xAE, 0xA4, 0x92, 0x74, 0xD8}; // mac adress of the wifi module
void main(void) {
unsigned char cch;
char strTxtp[cchRxMax];
// UART_InitPoll(Baudrate);
LCD_Init(); //initialize LCD screen
LCD_WriteStringAtPos(" UART Data test", 0, 0);
UART_InitPoll(Baudrate);
SYSTEM_Initialize();
// shell_init(Baudrate); //initialise baudrate for sending over to esp32
delayMS(100);
printString("checking AT status: \n\r");
checkAT();
printString("setting wifi mode: \n\r");
setWiFiMode(1);
delayMS(100);
printString("getting wifi mode:\n\r");
getWiFiMode();
delayMS(100);
printString("setting AP \n\r");
setCurrentAP(&conectionName[0], &password[0], NULL);
delayMS(100);
printString("getting AP connection \n\r");
getCurrentAP();
// void setCurrentAP(char * ssid, char * pwd, char * bssid) {
getDeviceInfo();
delayMS(100);
int i;
for(i = 1; i <= 0xF0; i = i << 1) {
LATA = i;
delayMS(100);
LATA = 0;
delayMS(100);
}
//write to the LCD as well
LCD_DisplayClear();
//enable errorlog first to show all errors
show_errorlog(1);
printString("connecting to timeserver \n\r");
esp_to_ntp(enable, timezone, &ntpServer[0]);
delayMS(100);
printString ("check time configuration \n\r");
getTimeConfig();
delayMS(100);
printString("configure user for MQTT connection \n\r");
config_user(linkID, scheme, &ClientId[0], &username[0], &MQTTpassword[0], cert_key_ID, CA_ID, &path[0]);
delayMS(100);
// printString(" show queury mqtt broker connections\n\r");
// MQTT_brokerConnections();
// delayMS(100);
// printString("connect user to broker \n\r");
// Connect_to_broker(linkID, &host[0], port, reconnect);
// delayMS(100);
//// printString(" show queury mqtt broker connections again\n\r");
//// MQTT_brokerConnections();
//// delayMS(100);
// printString("subscribing to a topic \n\r");
// Sub_to_topic(linkID, &topic[0], qos);
// delayMS(100);
// printString("publish to a topic \n\r");
// Pub_to_topic(linkID, &topic2[0], &data[0], qos, retain);
while(1) {
// if(-1 == establishSSLConnection("192.168.1.104", 4443)) {
// delayMS(1000);
// } else {
// uint8_t status = getServerStatus("192.168.1.104", 4443);
// switch(status) {
// case 0:
// delayMS(1000);
// break;
// case 1:
// blinkLED(0);
// break;
// case 2:
// blinkLEDS();
// break;
// case 3:
alternateLEDS();
// break;
// default:
// delayMS(1000);
// break;
// }
// }
/*
if(UART_AvaliableRx()){
printString("rdy to sent to esp32 \n\r");
cch = UART_GetCharPoll();
//use the LCD display to visualize the received chars
printf(strTxtp, " Received %c", cch);
printString("chars received on lcd \n\r");
LCD_WriteStringAtPos(strTxtp, 1, 0);
//send the char back to UART
printString("show sent char:\n\r");
UART_PutChar(cch);
printString("\n\r");
printString("chars sent to uart\n\r");
printString("rdy to receive data:\n\r");
}*/
}
}
This is the function where I try to setting the userconfig:
//configure user settings for MQTT connection
void config_user(unsigned int linkID, unsigned int scheme, char *ClientId, char *username, char *password, unsigned int cert_key_ID, unsigned int CA_ID, char *path) {
printString("Configure user settings for MQTT connection...\r\n");
char tx[0];
sprintf(tx, "at+mqttusercfg=%d,%d,\"%s\",\"%s\",\"%s\",%d,%d,\"%s\"\r\n", linkID, scheme, ClientId, username, password, cert_key_ID, CA_ID, path);
sendToESP(tx);
delayMS(20);
while(!(UART1_StatusGet() & UART1_RECEIVER_IDLE )) {
// Wait for the data to fill the RX buffer
}
char rx[RX_BUF_SIZE];
char * cur = rx;
while(UART1_ReceiveBufferSizeGet() < 512) {
*cur++ = UART1_Read();
}
*cur = '\0';
printString(rx);
}
I'd really appreciated if someone could help me with this. I personally think it has to do with login creditentials but i am not sure about this.
Also since I am a new user I cannot include links to external sites, so sorry in advance for that I have to show it like this.
-
Attachment: picture1.png
(Size: 33.01KB, Downloaded 323 times) -
Attachment: picture2.png
(Size: 221.92KB, Downloaded 390 times) -
Attachment: picture3.png
(Size: 2.12MB, Downloaded 357 times)
|
|
|
Goto Forum:
Current Time: Mon Dec 30 16:46:27 GMT 2024
Powered by FUDForum. Page generated in 0.03089 seconds
|