Hello all, I have recently gotten two separate functions working but when combining I am having trouble publishing data to an MQTT broker. The command "client.connect("LaunchPadClient");" is causing my launchpad to stop operation. I am using the MSP4305529 & CC3100.
The libraries I have combined for this particular project are:
CounterLib_t
WiFi.h
SPI.h
PubSubClient.h
The code where the problem portion occurs:
void wifiPrintout()
{
// read the input on analog pin:
int sensorValue = (analogRead(24));
Serial.println(sensorValue);
// convert into to char array
String str = (String)sensorValue;
int str_len = str.length() + 1; // Length (with one extra character for the null terminator)
char char_array[str_len]; // Prepare the character array (the buffer)
str.toCharArray(char_array, str_len); // Copy it over
wifiConnect();
Serial.println("testA");
// publish data to MQTT broker
if (client.connect("LaunchPadClient")) { /********* this line of code *************/
Serial.println("testLoop");
client.publish("MyData", char_array);
//client.subscribe("MyData");
Serial.println("Publishing successful!");
client.disconnect();
}
Serial.println("testB");
}
The output in Serial Monitor:
3422 Start WiFi SSID: HomeWiFi IP Address: 192.168.0.19 testA
You can see the loop is never entered since the testLoop nor testB are output to the serial monitor.
Originally I had problems with the WiFi connection in conjunction with my input signal on P2.2 for the timer signal used in the counter library where my WiFi would stall (the wifiConnect() command), so I moved my input signal to P1.0 and this cleared this bug up but I am still not able to establish a connection with the client. Any thoughts? Also I am sure this is all correct I have tested it in a separate sketch without the counter library and counter functions and it publishes the data with no problem.