orpeleg7 0 Posted November 24, 2014 Share Posted November 24, 2014 Hi there, I am using a CC3200 launchpad, together with Energia 13. I am trying to connect the launchpad through MQTT to publish and receive messages (following Adrian Fernandez youtube on and blog on http://energia.nu/creating-an-iot-connected-sensor-with-energia-mqtt/). I succeeded on publishing information through MQTT to Node-Red, twitter etc., however I did not have any luck in subscribing. Since the blog (nor the video) does not state explicitly how to subscribe, my guess is that I have something wrong in my definitions. In the cloud side I am using Bluemix cloud, with Node-Red service. I simply define an input and output MQTT, and a debug node. The input works well, however the output (from the cloud to the launcpad) does not work. The output MQTT is defined with the same broker as the input MQTT, however with a different topic (matching the definition in the launchpad side). On the launcpad side, I am using the PubSubClient library, with the following commands to subscribe: if (client.connect("LaunchPadClient")) { client.publish("outTopic", char_array); client.subscribe("PelegInTopic"); Serial.println("Connection successful!"); client.disconnect(); } The callback function is never activated (it simply contains a serial message declaring input, however it never appears). *code attached. CAN ANYONE HELP???? Thanks a lot, Or Peleg MQTT_test.ino Quote Link to post Share on other sites
energia 485 Posted November 24, 2014 Share Posted November 24, 2014 What a coincidence (or isn't it?), I was just finishing up and testing the improved MQTT examples. Quick look at your Sketch shows that you are missing the client.loop() in the loop function. This call will service any outstanding messages that came in and call your callback. Thank you for providing detailed information. This helps a lot with not having to guess or ask about details! Below is a example Sketch that I just finished up: /* Basic MQTT example - connects to an MQTT server - publishes "hello world" to the topic "outTopic" - subscribes to the topic "inTopic" */ #include <SPI.h> #include <WiFi.h> #include <PubSubClient.h> // your network name also called SSID char ssid[] = "energia1"; // your network password char password[] = "launch pad"; // MQTTServer to use char server[] = "iot.eclipse.org"; void callback(char* topic, byte* payload, unsigned int length) { Serial.print("Received message for topic "); Serial.print(topic); Serial.print("with length "); Serial.println(length); Serial.println("Message:"); Serial.write(payload, length); Serial.println(); } WiFiClient wifiClient; PubSubClient client(server, 1883, callback, wifiClient); void setup() { Serial.begin(115200); // Start Ethernet with the build in MAC Address // attempt to connect to Wifi network: Serial.print("Attempting to connect to Network named: "); // print the network name (SSID); Serial.println(ssid); // Connect to WPA/WPA2 network. Change this line if using open or WEP network: WiFi.begin(ssid, password); while ( WiFi.status() != WL_CONNECTED) { // print dots while we wait to connect Serial.print("."); delay(300); } Serial.println("\nYou're connected to the network"); Serial.println("Waiting for an ip address"); while (WiFi.localIP() == INADDR_NONE) { // print dots while we wait for an ip addresss Serial.print("."); delay(300); } Serial.println("\nIP Address obtained"); // We are connected and have an IP address. // Print the WiFi status. printWifiStatus(); } void loop() { // Reconnect if the connection was lost if (!client.connected()) { Serial.println("Disconnected. Reconnecting...."); if(!client.connect("energiaClient")) { Serial.println("Connection failed"); } else { Serial.println("Connection success"); if(client.subscribe("inTopic")) { Serial.println("Subscription successfull"); } } } if(client.publish("outTopic","hello world")) { Serial.println("Publish success"); } else { Serial.println("Publish failed"); } // Check if any message were received // on the topic we subsrcived to client.loop(); delay(1000); } void printWifiStatus() { // print the SSID of the network you're attached to: Serial.print("SSID: "); Serial.println(WiFi.SSID()); // print your WiFi IP address: IPAddress ip = WiFi.localIP(); Serial.print("IP Address: "); Serial.println(ip); // print the received signal strength: long rssi = WiFi.RSSI(); Serial.print("signal strength (RSSI):"); Serial.print(rssi); Serial.println(" dBm"); } orpeleg7 1 Quote Link to post Share on other sites
chintanp 0 Posted June 19, 2015 Share Posted June 19, 2015 Dear Fellows, So I got a new CC3100 Booster Pack, and out of box, decided to try the IOT-MQTT example with energia. While energia did run the basic AnalogSerialRead example perfectly with my potentiometer, I wasnt able to move past that. I got the MQTT code as in the example from the PubSubClient - potentiometer example, and made necessary changes like updating my ssid and pwd, also changed the corresponding pin etc. I compiled and uploaded the code. Upon resetting my TIVA-C TM4C123GXL launchpad, the Serial monitor printed the first message "Start Wifi", and then hung indefintely, no response after that. I even tried with the code shown above. Same behavior, the serial monitor prints "Attempting to connect to network named: mySSID " and then hangs. To debug, I put a print statement just before the while loop while ( WiFi.status() != WL_CONNECTED) { like so : Serial.println(WiFi.status()), to see if the status was incorrect. But this didnt get printed. This means that the code hangs on the prev line, i.e. WiFi.begin(ssid, password); How can I debug this further/resolve this ? I am using the default firmware on my CC3100 boosterpack. I dont have the CC3100EMU, would I need to make any updates, or import any library in energia? Quote Link to post Share on other sites
bluehash 1,581 Posted June 22, 2015 Share Posted June 22, 2015 Is your password in Ascii? See: https://hackaday.io/project/3002/log/9649-first-steps-with-cc3200 Quote Link to post Share on other sites
guycs 1 Posted July 31, 2017 Share Posted July 31, 2017 Quote client.loop() in the loop function. This call will service any outstanding messages that came in and call your callback @energia This polling kind of solution is somehow ruin the whole beauty of using the event handler as it slows down the response to received topics and turns it to be non deterministic as it is dependent on the program flow, Is there other way of doing it that would be functioning like a real event handler or interrupt? Also, @orpeleg7 nice catch make me wonder if anyone at TI is running the example programs at all, before they are being added to the released libraries? Thanks Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.