Jump to content


  • Content Count

  • Joined

  • Last visited

Posts posted by nitred

  1. Hello, I have some updates.


    Unfortunately I haven't found a fix for my specific scenario where a particular router is exhibiting problems when the cc3200 transitions from AP to Station but another router seems to work fine, but I have a few observations and suggestions .


    1) When the cc3200 is connected/connecting to a router as a Station the WiFi._connecting flag is set to 'true'. But when it transitions into an Access Point, then the WiFi._connecting flag is NOT reset back to 'false'

    • Suggestion: "_connecting = false;" should be included at the end of WiFi.beginNetwork()
        /* Restart Network processor */
        retVal = sl_Stop(30);
        role = ROLE_AP;
        _connecting = false;    // AP FIX
        return sl_Start(NULL,NULL,NULL);

    2) When transitioning from AP to Station, the NWP must be restarted as mentioned in Wlan.h


    \warning   After setting the mode the system must be restarted for activating the new mode  

        \par       Example:
                    //Switch from any role  to STA:
    • Suggestion: Include the following code which is within "AP FIX" TAGS into WiFi.begin() method of WiFi.cpp file
        //initialize the simplelink driver and make sure it was a success
        bool init_success = init();
        if (!init_success) {
            return WL_CONNECT_FAILED;
        // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< AP FIX
        if(role != ROLE_STA){
            role = ROLE_STA;
        // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< AP FIX END
        // Set IP address configuration to DHCP if needed

    3) @@PaoloIT , the fixes you mentioned before do exactly the same things as I mentioned above but they also call WiFi.init() and sl_WlanConnect() everytime you call WiFi.begin(). This is not good practice since not everyone is going to be careful in calling WiFi.begin(). I'd really appreciate it if you could test my fixes on your end.


    4) The fixes that I mentioned are in no way exhaustive. I don't know enough of such indepth networking to be sure of what all needs to be done before and after transition from AP to STA mode. As mentioned in one of the functions of Wlan_station example of CC3200 CCS SDK the following are some possibilities.

    //! \brief This function puts the device in its default state. It:
    //!           - Set the mode to STATION
    //!           - Configures connection policy to Auto and AutoSmartConfig
    //!           - Deletes all the stored profiles
    //!           - Enables DHCP
    //!           - Disables Scan policy
    //!           - Sets Tx power to maximum
    //!           - Sets power policy to normal
    //!           - TBD - Unregister mDNS services
    //! \param   none
    //! \return  On success, zero is returned. On error, negative is returned
    static long ConfigureSimpleLinkToDefaultState()
        SlVersionFull   ver = {0};
        unsigned char ucVal = 1;
        unsigned char ucConfigOpt = 0;
        unsigned char ucConfigLen = 0;
        unsigned char ucPower = 0;
        long lRetVal = -1;
        long lMode = -1;
        lMode = sl_Start(0, 0, 0);
        ASSERT_ON_ERROR(__LINE__, lMode);
        // Get the device's version-information
        // Set connection policy to Auto + SmartConfig 
        //      (Device's default connection policy)
        lRetVal = sl_WlanPolicySet(SL_POLICY_CONNECTION, 
                                    SL_CONNECTION_POLICY(1, 0, 0, 0, 1), NULL, 0);
        ASSERT_ON_ERROR(__LINE__, lRetVal);
        // Remove all profiles
        lRetVal = sl_WlanProfileDel(0xFF);
        ASSERT_ON_ERROR(__LINE__, lRetVal);
        // If the device is not in station-mode, try putting it in staion-mode
        if (ROLE_STA != lMode)
            if (ROLE_AP == lMode)
                // If the device is in AP mode, we need to wait for this event 
                // before doing anything
            // Switch to STA role and restart
            lRetVal = sl_WlanSetMode(ROLE_STA);
            ASSERT_ON_ERROR(__LINE__, lRetVal);
            lRetVal = sl_Stop(SL_STOP_TIMEOUT);
            ASSERT_ON_ERROR(__LINE__, lRetVal);
            // reset status bits
            lRetVal = sl_Start(0, 0, 0);
            ASSERT_ON_ERROR(__LINE__, lRetVal);
            // Check if the device is in station again
            if (ROLE_STA != lRetVal)
                // We don't want to proceed if the device is not up in STA-mode
                return DEVICE_NOT_IN_STATION_MODE;
        // Device in station-mode. Disconnect previous connection if any
        // The function returns 0 if 'Disconnected done', negative number if already
        // disconnected Wait for 'disconnection' event if 0 is returned, Ignore 
        // other return-codes
        lRetVal = sl_WlanDisconnect();
        if(0 == lRetVal)
            // Wait
        // Enable DHCP client
        lRetVal = sl_NetCfgSet(SL_IPV4_STA_P2P_CL_DHCP_ENABLE,1,1,&ucVal);
        ASSERT_ON_ERROR(__LINE__, lRetVal);
        // Disable scan
        ucConfigOpt = SL_SCAN_POLICY(0);
        lRetVal = sl_WlanPolicySet(SL_POLICY_SCAN , ucConfigOpt, NULL, 0);
        ASSERT_ON_ERROR(__LINE__, lRetVal);
        // Set Tx power level for station mode
        // Number between 0-15, as dB offset from max power - 0 will set max power
        ucPower = 0;
        lRetVal = sl_WlanSet(SL_WLAN_CFG_GENERAL_PARAM_ID, 
                WLAN_GENERAL_PARAM_OPT_STA_TX_POWER, 1, (unsigned char *)&ucPower);
        ASSERT_ON_ERROR(__LINE__, lRetVal);
        // Set PM policy to normal
        lRetVal = sl_WlanPolicySet(SL_POLICY_PM , SL_NORMAL_POLICY, NULL, 0);
        ASSERT_ON_ERROR(__LINE__, lRetVal);
        // Unregister mDNS services
        lRetVal = sl_NetAppMDNSUnRegisterService(0, 0);
        ASSERT_ON_ERROR(__LINE__, lRetVal);
        lRetVal = sl_Stop(SL_STOP_TIMEOUT);
        ASSERT_ON_ERROR(__LINE__, lRetVal);
        return lRetVal; // Success

     So there's definitely more that needs to be done to make it 'stable'.

  2. Hello I have a few updates,


    1) Please ignore my earlier suggestion of including "WiFi._initialized = false;" & "WiFi._connecting = false;" in the WiFiClient.cpp file. Instead include those two lines of code in the Energia program before WiFi.begin() because they may cause some checks and balances to fail.


    2) Be sure to include "WiFi._connecting = false;" before WiFi.begin() only when you're sure that you haven't called WiFi.begin() elsewhere in your code.


    3) I've noticed that some routers seem to fail during the transition from STATION to AP to STATION in spite of the above mentioned solutions. When I try to transition from:

    • Belkin Router Station -> AccessPoint -> Belkin Router Station (The CC3200 almost never hangs)
    • Belkin Router Station -> AccessPoint -> TPLink Router Station (The CC3200 almost never hangs)
    • TPLink Router Station -> AccessPoint -> TPLink Router Station (Hangs almost always)
    • TPLink Router Station -> AccessPoint -> Belkin Router Station (Hangs almost always)

    (I'm not saying the brands of routers are good or bad, maybe just those models. Belkin Router Model - N600 DB and TP Link model - TL WR740N)


    4) I've also noticed that the transition from Station to AccessPoint never fails. @@spirilis is it possible that the Access Point never fails because of the following code in the WiFi.beginNetwork() in WiFi.cpp? And do you think it is safe to try to experiment with this for WiFi.begin() or rather find a way to software reset the CC3200 before doing a WiFi.begin()?

    /* Restart Network processor */
        retVal = sl_Stop(30);
        role = ROLE_AP;
        return sl_Start(NULL,NULL,NULL);
  3. The image found on the following link with CC3200 Launchpad should serve as a useful reference as to what each pin is capable of on the Energia Platform: http://energia.nu/wordpress/wp-content/uploads/2014/09/cc3200lppinmap.jpg

    You should use the pin numbers as seen in the image (black background with white numbers) to address every pin.


    Also you should look up this reference page which is similar to the Arduino and it is perhaps the best place to start to learn each pin config : http://energia.nu/reference/

  4. Hi I have no idea about Tiva, but I just looked it up and I see that it is just a launchpad and I have some experience with CC3200 Lanuchpad.


    I was wondering about your problem and a doubt popped up as to how the Tiva knows what today's date is? Are you using an RTC?

  5. I'm working on CC3200. I know it says 256KB of RAM but I'm quite certain all that isn't available for stack or even for program memory because on Energia 13, my program size went upto about 80KB and Energia would complain that I'm over using memory by 8 Bytes. (I had to remove Serial debugs entirely for it to successfully compile). Luckily Energia 14 was released soon and the same program went only up to about 40KB.


    As to my current program, I went ahead and dropped Serial debugs entirely (including removing Serial.begin), I seemed to have saved about 3KB of program memory (And I'm sure some stack space as well) but the issue persists.


    I just realized that my buffer is pre-declared when you pointed it out, and it only makes it so much more strange!


    Any suggestions to fix it and possible causes for the issue please? Any chance I'm looking in the wrong place? It took me a lot of time to find the issue because my code flow seemed pretty OK. The variables seem to change their value right after I call "SerFlash.readBytes". I even tried using "volatile" before the data type of the variable wondering if this is some strange interrupt based issue.



  6. Hi @@spirilis I've been having a few problems with the library/RAM.



    1) My program is pretty long

    2) I have many global variables (approximately 40) 

    3) I update the global variables in several functions. I usually get data from a UDP or TCP socket and put the data into these variables.

    4) I then take the data from the global variables and update a FILE (using your library)


    # The problem I'm having is that, the moment I read the FILE into my BUFFER, it seems to OVERWRITE a few of my global variables with data from the FILE.


    Here's a general example : (Please note that my actual code is pretty huge compared to the example. The example is used to illustrate the issue only, and I don't think you'll be able to replicate the issue on this example)

    uint8_t global_variable = 15;
    uint8_t flash_buffer[512];
    void setup(){
        Serial.println(global_variable);               // >>>>>>>> OUTPUT : 15
        SerFlash.open("TEST.txt", FS_MODE_OPEN_READ);  // "TEST.txt" is already created with 512 bytes as filesize
        SerFlash.readBytes(flash_buffer, 512);
        Serial.println(global_variable);               // >>>>>>>> OUTPUT : 0     <<<<<<<< THIS IS THE PROBLEM, I LOSE MY OLD DATA
        flash_buffer[45] = global_variable;            // updating a particular byte in the buffer
        SerFlash.write(flash_buffer, 512);
        Serial.println(global_variable);               // >>>>>>>> OUTPUT : 0 <<<<<<<< I HAVE DEFINITELY LOST MY OLD DATA
    void loop(){

    Here's a few observations:

    1) This happens not just to one variable, but several global variables. This is a pretty big issue since I have some global flags that get SET / RESET whenever I have a FILE operation and throws my program out of sync.

    2) I'm guessing that I'm on the limit of my RAM usage and when I load 512 new bytes into the "flash_buffer", some of the global variables' addresses get overwritten.


    I know I have to reduce my RAM footprint but do you have any other Suggestions?

    1) Will putting global variables into STRUCTs help?

    2) Can I have file sizes of 128 bytes?

    3) Could there be an issue with the library itself in terms of offsets and writing to the wrong location?

    4) Anything other suggestions to get rid of the problem?




  7. Hey @@PaoloIT , it works great!


    Just one note, since you're asking us to add

    - "WiFi._initialized = false;"

    "WiFi._connecting = false;"

    before WiFi.begin(*char ssid, *char pass) every time inside the sketch, I went ahead and added the two lines into the "WiFi.begin(*char ssid, *char pass)" method inside the WiFi.cpp file instead of adding them in my sketch.


    Everything seems to work fine with that too (I hope what I did doesn't mess things up).


    To make sure nothing is broken, I tested it in the following way:

    [AP--->UDP.begin()----->Station---->UDP.begin()----->AP...]  x 10    (ten times)


    To be honest the CC3200 switched between networks faster than I could on my laptop :|

    Anyway it seems to work fine :)


  8. I don't think the API is fully compatible with other Libraries or Arduino's. I think I'll slowly work towards it.


    At the moment however I'm not sure there's libraries that will work with the CC3200 Launchpad so I was just filling the space, since I needed an RTC Library for myself. I'm more than happy to deprecate this one if a better library comes up.


    Thanks for the direction igor.

  9. Hi,


    I've made a very simple RTC library using the RTC method in the PRCM library.


    It is intended for the CC3200 Launchpad and has only been tested on the CC3200 Launchpad so far.



    • Uses the PRCM library
    • It follows UNIX Time
    • It was made with the "Time" library of the Sparkcore in mind.
    • It has the following methods:
      • ccRTC.zone()
      • ccRTC.now()
      • ccRTC.year()
      • ccRTC.month()
      • ccRTC.day()
      • ccRTC.weekday()
      • ccRTC.hour()
      • ccRTC.minute()
      • ** ccRTC.begin()

    Limitations: (Unfortunately there are a few actual limitations)

    • It is accurate to only about 4 seconds an hour. (That is pretty bad, but can it can be used for non time critical applications if time is synced with an online server regularly)
    • My tests haven't shown any issues so far, but it is not foolproof yet.
    • If you're using an NTP server to sync time, then you'll need to convert it to UNIX time first before you use the ccRTC.setTime()


    You can get the code and a basic guide from here : https://github.com/nitred/ccRTC

    Additional Documentation for the the functionality can be found here : http://docs.spark.io/firmware/#libraries-timeIt


    Its a work in progress and I know for a fact that there's a better way to do it than this but I really needed this library and I hope you find it helpful too. Any and all feedback and improvements are welcome!


  10. Hi,


    I'm using a cc3200 Launchpad. On my first run, I provided the SSID and Passphrase to connect to my router as shown below:

    char ssid[] = "testrouter";
    char passphrase[] = "testpassphrase";
    WiFi.begin(ssid, passphrase);

    I've noticed that there was a recent addition into the WiFi.begin(ssid, pass) method in the WiFi.cpp file which seems to add the SSID and Passphrase into its own profile.

     if (iRet == 0) {
            sl_WlanProfileAdd(ssid, NameLen, 0, &SecParams, 0, 6, 0);
            _connecting = true;
            return status();
        } else {
            return WL_CONNECT_FAILED;

    I'm having issues when I'm trying to retrieve the profile using the "int sl_WlanProfileGet()" method. I'm able to retrieve the SSID but unable to retrieve the Passphrase correctly. Following is the code I'm using to retrieve the SSID and Passphrase:

    char pName[32];
    int pNameLen;
    unsigned char pMacAddr[8];
    SlSecParams_t *pSecParams;
    SlGetSecParamsExt_t *pSecExtParams;
    unsigned long pPriority;
    sl_WlanProfileGet(0, pName, &pNameLen, pMacAddr, pSecParams, pSecExtParams, &pPriority);  // index 0
    pName[pNameLen] = '\0';
    pSecParams->Key[pSecParams->KeyLen] = '\0';
    Serial.println(pName);              // prints "testrouter"    -CORRECT
    Serial.println(pSecParams->Type);   // prints 2               -CORRECT (SL_SEC_TYPE_WPA)
    Serial.println(pSecParams->Key);    // prints "" -WRONG
    WiFi.begin(pName, pSecParams->Key); // doesn't connect successfully

    Please let me know if I'm doing something wrong or if there is another way to connect to a past profile? Thanks!


    Edit: My actual problem is that, if I do Smartconfig and I successfully send the SSID and Passphrase to the CC3200 and it connects to WiFi router but the CC3200 powers OFF and then powers ON again, how do I make it connect to the last known SSID and passphrase without having to do Smartconfig again?

  11. I added to craggmire's example a little bit and it works great!


    My only issue is that SerFlash.write was able to take "HelloWorld" as the only argument without a 'len' argument:

    size_t SLFS::write(const uint8_t *buffer, size_t len).


    I made sure to SerFlash.close() after every SerFlash.open() because I'm assuming that's how files are supposed to be handled. I could be wrong.


    Note: I used the latest "SLFS" files from Spirilis' github page. I used the latest files of "/hardware/cc3200/libraries/WiFi" & "/hardware/cc3200/cores/cc3200" from the Energia github page.


    Here's the example below:

    #include <SLFS.h>
    #include <WiFi.h>
    #include <SPI.h>
    char flash_buffer[128];
    void setup()
      pinMode(RED_LED, OUTPUT);
      digitalWrite(RED_LED, HIGH);
      delay(5000);      // wait for a bit
      digitalWrite(RED_LED, LOW);
      SerFlash.begin(); // <====== Essential! Initiates the SimpleLink API and DMA channels.
      Serial.println("Start & Create");
      SerFlash.open("myfile.txt", FS_MODE_OPEN_CREATE(1024, _FS_FILE_OPEN_FLAG_COMMIT));
      SerFlash.close();    // I'm assuming this is good practice
      SerFlash.open("myfile.txt", FS_MODE_OPEN_WRITE);
      SerFlash.write("HelloWorld");  // 10 characters
      SerFlash.open("myfile.txt", FS_MODE_OPEN_READ);
      SerFlash.readBytes(flash_buffer, 11);
      flash_buffer[11] = '\0';  // making sure that trailing character is an EOF
      Serial.print("READ DATA: ");
    void loop()
      digitalWrite(RED_LED, HIGH);
      digitalWrite(RED_LED, LOW);
  • Create New...