Skip to content

Commit

Permalink
spark_disable_wlan.h and spark_disable_cloud.h for complete user control
Browse files Browse the repository at this point in the history
  • Loading branch information
satishgn committed Mar 6, 2014
1 parent a565007 commit 0a08406
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 3 deletions.
40 changes: 40 additions & 0 deletions inc/spark_disable_cloud.h
@@ -0,0 +1,40 @@
/**
******************************************************************************
* @file spark_disable_cloud.h
* @author Satish Nair
* @version V1.0.0
* @date 6-March-2014
* @brief Header to be included to prevent the core from connecting to cloud
******************************************************************************
Copyright (c) 2013-14 Spark Labs, Inc. All rights reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation, either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, see <http://www.gnu.org/licenses/>.
******************************************************************************
*/

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __SPARK_DISABLE_CLOUD_H
#define __SPARK_DISABLE_CLOUD_H

class SparkDisableCloud {
public:
SparkDisableCloud()
{
SPARK_CLOUD_CONNECT = 0;
}
};

SparkDisableCloud sparkDisableCloud;

#endif /* __SPARK_DISABLE_CLOUD_H */
40 changes: 40 additions & 0 deletions inc/spark_disable_wlan.h
@@ -0,0 +1,40 @@
/**
******************************************************************************
* @file spark_disable_wlan.h
* @author Satish Nair
* @version V1.0.0
* @date 6-March-2014
* @brief Header to be included to prevent the core from starting the wlan
******************************************************************************
Copyright (c) 2013-14 Spark Labs, Inc. All rights reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation, either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, see <http://www.gnu.org/licenses/>.
******************************************************************************
*/

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __SPARK_DISABLE_WLAN_H
#define __SPARK_DISABLE_WLAN_H

class SparkDisableWlan {
public:
SparkDisableWlan()
{
SPARK_WLAN_START = 0;
}
};

SparkDisableWlan sparkDisableWlan;

#endif /* __SPARK_DISABLE_WLAN_H */
3 changes: 0 additions & 3 deletions inc/spark_utilities.h
Expand Up @@ -78,9 +78,6 @@ class RGBClass {

class SparkClass {
public:
SparkClass() {}
SparkClass(bool cloudConnect) {SPARK_CLOUD_CONNECT = cloudConnect;}

static void variable(const char *varKey, void *userVar, Spark_Data_TypeDef userVarType);
static void function(const char *funcKey, int (*pFunc)(String paramString));
static void publish(const char *eventName);
Expand Down

14 comments on commit 0a08406

@satishgn
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Include the following files in application.cpp or WebIDE to disable Wlan / Cloud and execute the setup() and loop()

include "spark_disable_wlan.h"

include "spark_disable_cloud.h"

@nitred
Copy link

@nitred nitred commented on 0a08406 Mar 6, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Satish,
try 1 : #include "spark_disable_cloud.h"

  • My application code works right from the start without even having to wait for connection to the router or cloud.
  • But the spark doesn't seem to connect to my router. There's a constant Green Flash..
    try 2: #include "spark_disable_wlan.h"
  • My application code works right from the start, the led is breathing fast cyan and its not connecting to router as expected

** I see that you've deleted two lines of code. That function was incredibly useful if I wanted to run code right from the start and at the same time have a connection to the router and the cloud. I tested it right before you made this commit.

** To build the application.cpp locally, I'm having to do "make clean" almost every time I change code or use different ".h" files. I never had to do that till date.

@satishgn
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hope you have pulled the latest commits including the one made after this one.

Now the following should be the behaviour with only #include "spark_disable_cloud.h" in application.cpp
you should be able to start the wlan and connect to Wifi router(assuming you have the right credentials) else without any profile, it will automatically enter smart config mode blinking blue and thus blocking your application. The RGB should flash GREEN(confusing?). If you run Spark.connect() within your application code, you should be able to connect to cloud. Without a Wifi connection, it should flash GREEN.

Now with #include "spark_disable_wlan.h" i.e. WLAN disabled, you should notice only fading WHITE and your application code should run at full speed.

I am in the process of writing up a Spark.wlan(bool) function which should help the user to start/stop wlan from application code.

The reason you see everything building up is because of the many changes done to dependency files in the past commits.

@nitred
Copy link

@nitred nitred commented on 0a08406 Mar 6, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My apologies, it seems like I haven't got the latest commit. I'll rerun the tests with the latest commits and I'll check if I get the expected behavior you just mentioned. Thanks :)

@satishgn
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In between I am going to push some change where successfully connected to WLAN will be displayed as SOLID GREEN. currently it FLASHES GREEN on successful AP connection.

@technobly
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

start the wlan and connect to Wifi router(assuming you have the right credentials) else without any profile,
it will automatically enter smart config mode blinking blue and thus blocking your application.
The RGB should flash GREEN(confusing?)

I'm guessing it should breathe green to let you know it successfully connected and still running. In this mode you should be able to talk to your Core over WLAN via UDP and TCP.

@satishgn
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@technobly , nice suggestion!

@mbeasley
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@satishgn I've pulled the most recent commits - just double checked to be sure. I'm just using #include "spark_disable_cloud.h to turn off cloud functionality but keep the wireless network up. You said that the flashing green light is expected, but my application isn't starting. I can remove the #include "spark_disable_cloud.h and flash the core, and everything works fine (other than that it connects to the cloud, which I'd like to remove). Do I need to anything other than this include?

@satishgn
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mbeasley, can you tell me what specifically you are trying to do via application.cpp, so I can try this out on my end to debug what's causing this issue?

@satishgn
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mbeasley, can you try this code and confirm D7 blinking?

    #include "application.h"
    //#include "spark_disable_wlan.h"
    #include "spark_disable_cloud.h"

    void setup()
    {
        pinMode(D7, OUTPUT);
        Serial.begin(9600);
    }

    void loop()
    {
        if(Serial.available())
        {
            char c = Serial.read();
            switch(c)
            {
            case 'w':
                //Spark.wlan(true);//Work in progress
                break;
            case 's':
                //Spark.wlan(false);//Work in progress
                break;
            case 'c':
                Spark.connect();
                break;
            case 'd':
                Spark.disconnect();
                break;
            }
        }

        //Indicates user loop running
        digitalWrite(D7, HIGH);
        delay(100);
        digitalWrite(D7, LOW);
        delay(100);
    }

@mbeasley
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@satishgn The above code works great, though it just guarantees that the loop is running, but not the WiFi connection. Though, that's good to see it gets to the loop.

To answer your previous question, I'm collecting and transmitting analog sensor data to a NodeJS TCP server. The code on the Core consists of:

  • A UDP listener for a broadcast message from the server to get the IP of the server
  • A TCP client to connect to that server
  • Once connected, analog reads of A0 and A1 are transmitted every 100ms to the TCP server

@towynlin
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a #include to accomplish this strikes me as clunky. Can we make this a #define or #undef macro instead? Best would be a one-line C++ syntax command rather than a preprocessor directive.

@satishgn
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@towynlin , can we pass compiler macros via WebIDE through a pull down option? and if this could be done that would be conditional compilation. Users cannot change the WiFi/Cloud state at runtime using WiFi.xyz() or Spark.xyz().

@mbeasley, we pushed some commits today which should allow you to control both WiFi and cloud at runtime. In case if you disable wlan at startup using the include, you will need to check the WiFi.status() in your application code before starting a TCP server etc. Start the server once in the loop() instead of setup() only if (WiFi.status==WIFI_ON)

@davids5
Copy link

@davids5 davids5 commented on 0a08406 Mar 7, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@satishgn @towynlin @technobly

With both compile time and run time control there are some cool things but possibility of confusion and customer support issues.
What is the strategy?

I can see an incredible gains on free RAM, FLASH in the CT off/off listed below

What should the lib granularity be? common-lib build wifi-lib, and common-lib

What ever we choose I think it is best to lets keep #ifdefs to a minimum (use libs, stubs or macros)

wifi | spark
ct=off off (maximize free RAM, FLASH) do we stub out WIFI api with error returns or make it an undefined CT error
ct=on off do we stub out Spark, WIFI apis or CT error?
ct=on on have real APIs

Thouhgts?

Please sign in to comment.