pubnubiot

Can't publish data from CC3100 + MSP430F5529 on PUBNUB


I followed the following tutorial: http://www.pubnub.com/blog/pubnub-streaming-texas-instruments-iot/ step by step and I managed to compile and code and connect to my Wi-Fi access point. I think I managed to connect to PubNub (the code prints on the terminal screen "PubNub Set Up" but in the code there is no real verification that it was indeed set up.

I opened an account on PubNub and I named my channel "testing" (I named it the same in the code I uploaded - I checked that a million times) and when I go to the Dev Console and click on subscribe I can't see anything! I mean I can post messages through the Dev Console but what I really want to see are the messages from the CC3100. I checked the UART terminal on my computer and I see the data being printed constantly so I know it is working. I went over the tutorial again and again and I'm doing the same thing but it just doesn't work. Any help would be appreciated!

What am I missing?

Thanks


Solution

  • This answer is posted really late. I admit I forgot about this post so I just decided to update it (a few years late though).

    I started digging to try and see what was the problem and I think I found it. First of all, I saw that PubNub.publish() wasn't working properly with the json_String because the json_String was 90% gibrish. So I erased most of the code that constructed the json_String (the part that inserts the analog values) and made it simpler. I then also added a part of code at the end which was needed for proper performance of the client variable which I got off of a part of code which was used for an arduino based project using the CC3100.

    Anyway, the new code is the one below and now it works FINE! I finally see all the input streaming on PubNub! Thanks a lot! :D

    /*PubNub sample JSON-parsing client with WiFi support
     
      This combines two sketches: the PubNubJson example of PubNub library
      and the WifiWebClientRepeating example of the WiFi library.
     
      This sample client will properly parse JSON-encoded PubNub subscription
      replies using the aJson library. It will send a simple message, then
      properly parsing and inspecting a subscription message received back.
     
      This is achieved by integration with the aJson library. You will need
      a version featuring Wiring Stream integration, that can be found
      at http://github.com/pasky/aJson as of 2013-05-30.
     
      Please refer to the PubNubJson example description for some important
      notes, especially regarding memory saving on Arduino Uno/Duemilanove.
      You can also save some RAM by not using WiFi password protection.
     
     
      created 30 May 2013
      by Petr Baudis
     
      https://github.com/pubnub/pubnub-api/tree/master/arduino
      This code is in the public domain.
      */
     
    #include <SPI.h>
    #include <WiFi.h>
    #include <PubNub.h>
    #include <aJSON.h>
     
    static char ssid[] = "NetSSID_Name";    // your network SSID (name)
    static char pass[] = "NetworkdPassword"; // your network password
    static int keyIndex = 0;               // your network key Index number (needed only for WEP)
    
    const static char pubkey[] = "pub-c-51eb45ec-b647-44da-b2aa-9bf6b0b98705";
    const static char subkey[] = "sub-c-7e78ed9c-991d-11e4-9946-02ee2ddab7fe";
    const static char channel[] = "testing";
     
    #define NUM_CHANNELS 4  // How many analog channels do you want to read?
    const static uint8_t analog_pins[] = {23, 24, 25, 26};    // which pins are you reading?
     
    void setup()
    {
        Serial.begin(9600);
     
            Serial.println("Start WiFi");
            WiFi.begin(ssid, pass);
            while(WiFi.localIP() == INADDR_NONE) {
              Serial.print(".");
              delay(300);
            }
        Serial.println("WiFi set up");
     
        PubNub.begin(pubkey, subkey);
        Serial.println("PubNub set up");
            delay(5000);
    }
     
    void loop()
    {
      
            WiFiClient *client;
      
            // create JSON objects
            aJsonObject *msg, *analogReadings;
            msg = aJson.createObject();
            aJson.addItemToObject(msg, "analogReadings", analogReadings = aJson.createObject());
            
            // get latest sensor values then add to JSON message
            /*for (int i = 0; i < NUM_CHANNELS; i++) {
              String analogChannel = String(analog_pins[i]);
              char charBuf[analogChannel.length()+1];
              analogChannel.toCharArray(charBuf, analogChannel.length()+1);
              int analogValues = analogRead(analog_pins[i]);
              aJson.addNumberToObject(analogReadings, charBuf, analogValues);
            }*/
     
            // convert JSON object into char array, then delete JSON object
            char *json_String = aJson.print(msg);
            aJson.deleteItem(msg);
            
            // publish JSON formatted char array to PubNub
        Serial.print("publishing a message: ");
        Serial.println(json_String);
            Serial.println(channel);
            client = PubNub.publish(channel, json_String);
            Serial.println(*client);
            free(json_String);
            
            if (!client) {
            Serial.println("publishing error");
            delay(1000);
            return;
        }
        client->stop();
            
        delay(500);
    }
    //- See more at: http://www.pubnub.com/blog/pubnub-streaming-texas-instruments-iot/#sthash.tbQXMIzw.dpuf