Spark Core and Temboo Light Monitor

Here is a project I worked on last weekend using Spark Core and Temboo. Temboo provides easy and fast access to different APIs. It provides different libraries to connect to Temboo services and access it. There is a great Spark Core port of Temboo Arduino library which I decided to use for this project.

This project uses a low cost Light Sensor to constantly monitor the light level. If it is below a particular level then call a Temboo Choreo. For this project I am using Nexmo library (Library\Nexmo\Voice\CaptureTextToSpeechPrompt) to call a particular phone number, speaks out a message and get input (digits). Temboo library provides a easy way to call any Choreo and get the return value. The return value may vary based on the Choreo we are using. It can XML or JSON. In this project I am using JSON return string.

As everybody knows parsing JSON/XML from a memory limited MCU is not that easy. For this reason Temboo library provides Output Filters to make it very easy to process the return values. The above link provides a detailed documentation on how to use Output Filters. The Nexmo’s return value in JSON format contains an element ‘digits’ which contains the user entered digit. In this sample if the digit is ‘1’ then the LED attached to D2 is turn on. When the light level goes above the limit the LED is turned off. Instead of LED we can connect anything more meaningful like a Relay control to turn on the light, etc…

Using the project

To use this project, you should configure the Temboo Nexmo library and save it to a profile (https://www.temboo.com/library/Library/Nexmo/Voice/CaptureTextToSpeechPrompt/). You should also have one Nexmo account either trial/paid. Replace the following #defines of temboo-light.ino with actual Temboo credentials.

// Your Temboo account name 
#define TEMBOO_ACCOUNT "<<temboo account>>"  
// Your Temboo app key name
#define TEMBOO_APP_KEY_NAME "<<temboo app key name>>"  
// Your Temboo app key
#define TEMBOO_APP_KEY "<<temboo app key>>"  

Replace the Temboo profile name (which is saved previously) at line no. 111 of temboo-light.ino

Also you have Replace the Spark Core credentials in the temboo.html page.

Screenshots

enter image description here

enter image description here

enter image description here

Demo Video

6 Likes

Very cool! I’m always forgetting to turn on my porch light :smiley:

Thanks for sharing!
David

1 Like

Very nice post. It worked effortlessly on the first day. I am getting some sort of a warning message when I am compiling the code. I am pretty new to Spark and just playing around with it now. Here is the error message thrown while compiling. The error message was very long. I have just posted the starting and ending of the error. Please help me to fix this.

In file included from …/inc/spark_wiring.h:29:0,
from …/inc/application.h:29,
from Temboo/Temboo.h:32,
from Temboo/Temboo.cpp:87:
…/…/core-common-lib/SPARK_Firmware_Driver/inc/config.h:12:2: warning: #warning “Defaulting to Release Build” [-Wcpp] #warning "Defaulting to Release Build"
make: *** [Temboo/Temboo.o] Error 1
Error: Could not compile. Please review your code.

@MakerArun, can you post the entire error, you can copy only the error line and paste it here. So it will be clear where the issue is.

Thank you for looking in to this. Not sure if you had asked me to paste the entire error here.
sorry, there are too many lines in the console. Pasted the entire warning /error message.


In file included from ../inc/spark_wiring.h:29:0,
from ../inc/application.h:29,
from Temboo/Temboo.h:32,
from Temboo/Temboo.cpp:87:
../../core-common-lib/SPARK_Firmware_Driver/inc/config.h:12:2: warning: #warning "Defaulting to Release Build" [-Wcpp]
#warning  "Defaulting to Release Build"
^
In file included from /opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/backward/strstream:51:0,
from Temboo/Temboo.h:69,
from Temboo/Temboo.cpp:87:
/opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/backward/backward_warning.h:32:2:
 warning: #warning This file includes at least one deprecated or 
antiquated header which may be removed without further notice at a 
future date. Please use a non-deprecated interface with equivalent 
functionality instead. For a listing of replacement headers and 
interfaces, consult the file backward_warning.h. To disable this warning
 use -Wno-deprecated. [-Wcpp]

#warning \
^
In file included from /opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/bits/char_traits.h:39:0,
from /opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/ios:40,
from /opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/backward/strstream:53,
from Temboo/Temboo.h:69,
from Temboo/Temboo.cpp:87:
/opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/bits/stl_algobase.h:239:56: error: macro "min" passed 3 arguments, but takes just 2

min(const _Tp& __a, const _Tp& __b, _Compare __comp)
^
/opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/bits/stl_algobase.h:260:56: error: macro "max" passed 3 arguments, but takes just 2
max(const _Tp& __a, const _Tp& __b, _Compare __comp)
^
In file included from Temboo/ChoreoInputSet.h:26:0,
from Temboo/Temboo.h:76,
from Temboo/Temboo.cpp:87:
Temboo/TembooGlobal.h:29:0: warning: "pgm_read_byte" redefined [enabled by default]
#define pgm_read_byte(address) (*address)
^
In file included from Temboo/Temboo.cpp:87:0:
Temboo/Temboo.h:29:0: note: this is the location of the previous definition
#define pgm_read_byte(address_short) (*address_short)
^
In file included from ../inc/application.h:29:0,
from Temboo/Temboo.h:32,
from Temboo/Temboo.cpp:87:
/opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/bits/stl_algobase.h:193:5: error: expected unqualified-id before 'const'
min(const _Tp& __a, const _Tp& __b)
^
/opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/bits/stl_algobase.h:193:5: error: expected ')' before 'const'
/opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/bits/stl_algobase.h:193:5: error: expected ')' before 'const'
/opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/bits/stl_algobase.h:193:5: error: expected initializer before 'const'
/opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/bits/stl_algobase.h:216:5: error: expected unqualified-id before 'const'
max(const _Tp& __a, const _Tp& __b)
^
/opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/bits/stl_algobase.h:216:5: error: expected ')' before 'const'
/opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/bits/stl_algobase.h:216:5: error: expected ')' before 'const'
/opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/bits/stl_algobase.h:216:5: error: expected initializer before 'const'
In file included from /opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/bits/char_traits.h:39:0,
from /opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/ios:40,
from /opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/backward/strstream:53,
from Temboo/Temboo.h:69,
from Temboo/Temboo.cpp:87:
/opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/bits/stl_algobase.h:239:5: error: 'std::min' declared as an 'inline' variable
min(const _Tp& __a, const _Tp& __b, _Compare __comp)
^
/opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/bits/stl_algobase.h:239:5: error: template declaration of 'const _Tp& std::min'
/opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/bits/stl_algobase.h:242:7: error: expected primary-expression before 'if'
if (__comp(__b, __a))
^
/opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/bits/stl_algobase.h:242:7: error: expected '}' before 'if'
/opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/bits/stl_algobase.h:244:7: error: expected unqualified-id before 'return'
return __a;
^
/opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/bits/stl_algobase.h:260:5: error: 'max' declared as an 'inline' variable
max(const _Tp& __a, const _Tp& __b, _Compare __comp)
^
/opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/bits/stl_algobase.h:260:5: error: template declaration of 'const _Tp& max'
/opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/bits/stl_algobase.h:263:7: error: expected primary-expression before 'if'
if (__comp(__a, __b))
^
/opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/bits/stl_algobase.h:263:7: error: expected '}' before 'if'
/opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/bits/stl_algobase.h:265:7: error: expected unqualified-id before 'return'
return __a;
^
/opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/bits/stl_algobase.h:266:5: error: expected declaration before '}' token
}
^
make: *** [Temboo/Temboo.o] Error 1
Error: Could not compile. Please review your code.

@MakerArun, now I am also getting the same error, the interesting thing is that it was working when I posted the sample. Still looking into it.

Any news on this one? I’m getting the same error, seems to be related to stl_algobase, which is included from various other places.

Same here! Getting the same error message, any idea what causes this?

Hi @littledino2112

If you are getting the same error about min and max, you can undefine the macros used for the Arduino-compatible wiring definitions before any include files in your main sketch:

#undef min
#undef max
1 Like