Filter results by

Temboo Arduino Library

LibArduino is bundled with the Temboo library to make integration of various Web services possible. By using the powerful yet simple Temboo automatic code generation scheme, your sketch could be:

  • Pulling images from Instagram to display on your ARTIK-based picture frame display
  • Scanning articles from the NY Times to light an LED and play a sound effect when it finds a specified topic of interest
  • Sending your Simband race competition stats to your selected Facebook friends.

In this article, we offer an example of how you could use the Arduino Temboo library to auto-generate code for an ARTIK sketch to retrieve current weather information from Yahoo Weather.

Prerequisites

Before starting, you must have:

  • Installed the Arduino IDE

  • Created an account at Temboo.

Follow the steps below.

Auto-Generate the Code

  1. Log into Temboo.

  2. Go to Yahoo > Weather and select the GetWeatherByAddress Choreo.

  3. Turn ON IoT Mode if not on already.

  4. Select Arduino as your target board from the drop-down menu.

  5. Select your ARTIK Internet connection. For example, if you are using Wi-Fi®, select “Arduino WiFi” from the “How is it connected?” drop-down list; select the correct Wi-Fi Security Type, and enter your Wi-Fi SSID and password.

  6. Enter an address in the Address input field, e.g, 3665 N. 1st street, San Jose, CA

  7. Click the ‘Run’ button. In a moment, you should see Yahoo! Weather data in the OUTPUT section.

  8. Go farther down the page to find the auto generated Arduino code in the CODE section. It looks something like that shown below.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <SPI.h> 
#include <WiFi.h> 
#include <WiFiClient.h>
#include <Temboo.h> 
#include "TembooAccount.h" // contains Temboo account information

WiFiClient client; 

int numRuns = 1;   //Execution count, so this doesn't run forever 
int maxRuns = 10;   //Maximum number of times the Choreo should be executed  
 
void setup() {   
  Serial.begin(9600);      
  
    // For debugging, wait until the serial console is connected     
    delay(4000);   
  while(!Serial);   
    
  int wifiStatus = WL_IDLE_STATUS;   

  //Determine if the WiFi Shield is present   
  Serial.print("\n\nShield:");   
  if (WiFi.status()==WL_NO_SHIELD) {     
    Serial.println("FAIL");     

    //If there's no WiFi shield, stop here           
    while(true);   
  }    
    Serial.println("OK");     

  //Try to connect to the local WiFi network   
 while(wifiStatus!=WL_CONNECTED) {     
   Serial.print("WiFi:");     
   wifiStatus=WiFi.begin(WIFI_SSID, WPA_PASSWORD);      

   if(wifiStatus==WL_CONNECTED){       
     Serial.println("OK");     
   } else {       
     Serial.println("FAIL");     
   }     
   delay(5000);   
  }          
  Serial.println("Setup complete.\n");
}  
 
void loop() {   
 if (numRuns <= maxRuns) {     
    Serial.println("Running GetWeatherByAddress - Run #" + String(numRuns++));          
 
    TembooChoreo GetWeatherByAddressChoreo(client); 
  // Invoke the Temboo client        
    GetWeatherByAddressChoreo.begin();      

   // Set Temboo account credentials      
   GetWeatherByAddressChoreo.setAccountName(TEMBOO_ACCOUNT);        
   GetWeatherByAddressChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);       
    GetWeatherByAddressChoreo.setAppKey(TEMBOO_APP_KEY);          
 
  // Set Choreo inputs     
 String AddressValue =  "3665 N. 1st street, San Jose, CA";
  GetWeatherByAddressChoreo.addInput("Address", AddressValue);          
 
  // Identify the Choreo to run
GetWeatherByAddressChoreo.setChoreo("/Library/Yahoo/Weather/GetWeatherByAddress");          
  
// Run the Choreo; when results are available, print them to serial       
  GetWeatherByAddressChoreo.run();            
  while(GetWeatherByAddressChoreo.available())   {       
     char c = GetWeatherByAddressChoreo.read();       
     Serial.print(c);     
  }     
 
  GetWeatherByAddressChoreo.close();   
 }    
 
 Serial.println("Waiting...");   
 delay(30000); // wait 30 seconds between GetWeatherByAddress calls 
}

Prepare the Code for ARTIK

We'll now copy and adjust the generic Arduino code for ARTIK applications.

  1. Start a new sketch. Start a new sketch in the Arduino IDE.

  2. Copy the header. Copy the generated header file from the Temboo page to the Arduino IDE window.

  3. Copy the code. Copy the generated code to the Arduino IDE window.

  4. Remove SPI library reference. Since ARTIK 5 and 10 have built-in Wi-Fi / Ethernet support, there is no dependency on the Arduino SPI library. You can safely remove #include <SPI.h> from your code.

  5. Use ARTIK debugging. ARTIK uses DebugSerial for serial debugging, so change all instances of Serial in the code to DebugSerial.

  6. Change baud rate. ARTIK uses a baud rate of 115200, so change the first line in the setup() function to DebugSerial.begin(115200).

  7. Change GPIO pin numbers as needed. If you choose to use a GPIO pin to trigger your Choreo, or to use the Choreo to trigger a hardware event, verify that the GPIO pin numbers match the ones you are using; update them if not.

  8. Load and go! Compile and upload the sketch to ARTIK in the usual way.

You should see the Yahoo Weather Web service output like this on your terminal emulator.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
Running GetWeatherByAddress - Run #1
HTTP_CODE
0

//weather.yahoo.com/country/state/city-2488042/</link><pubDate>Mon, 25 Jul 2016 10:00 PM PDT</pubDate>
<yweather:condition code="31" date="Mon, 25 Jul 2016 10:00 PM PDT" temp="69" text="Clear"/>
<yweather:forecast code="32" date="25 Jul 2016" day="Mon" high="86" low="58" text="Sunny"/>
<yweather:forecast code="32" date="26 Jul 2016" day="Tue" high="92" low="57" text="Sunny"/>
<yweather:forecast code="32" date="27 Jul 2016" day="Wed" high="93" low="61" text="Sunny"/>
<yweather:forecast code="32" date="28 Jul 2016" day="Thu" high="93" low="63" text="Sunny"/>
<yweather:forecast code="32" date="29 Jul 2016" day="Fri" high="91" low="64" text="Sunny"/>
<yweather:forecast code="32" date="30 Jul 2016" day="Sat" high="87" low="62" text="Sunny"/>
<yweather:forecast code="34" date="31 Jul 2016" day="Sun" high="83" low="60" text="Mostly Sunny"/>
<yweather:forecast code="32" date="01 Aug 2016" day="Mon" high="84" low="58" text="Sunny"/>
<yweather:forecast code="32" date="02 Aug 2016" day="Tue" high="85" low="57" text="Sunny"/>
<yweather:forecast code="32" date="03 Aug 2016" day="Wed" high="86" low="57" text="Sunny"/>
<description>&lt;![CDATA[&lt;img src="http://l.yimg.com/a/i/us/we/52/31.gif"/&gt;
&lt;BR /&gt;
&lt;b&gt;Current Conditions:&lt;/b&gt;
&lt;BR /&gt;Clear
&lt;BR /&gt;
&lt;BR /&gt;
&lt;b&gt;Forecast:&lt;/b&gt;
&lt;BR /&gt; Mon - Sunny. High: 86Low: 58
&lt;BR /&gt; Tue - Sunny. High: 92Low: 57
&lt;BR /&gt; Wed - Sunny. High: 93Low: 61
&lt;BR /&gt; Thu - Sunny. High: 93Low: 63
&lt;BR /&gt; Fri - Sunny. High: 91Low: 64
&lt;BR /&gt;
&lt;BR /&gt;
&lt;a href="http://us.rd.yahoo.com/dailynews/rss/weather/Country__Country/*https://weather.yahoo.com/country/state/city-2488042/"&gt;Full Forecast at Yahoo! Weather&lt;/a&gt;
&lt;BR /&gt;
&lt;BR /&gt;
(provided by &lt;a href="http://www.weather.com" &gt;The Weather Channel&lt;/a&gt;)
&lt;BR /&gt;]&gt;
</description><guid isPermaLink="false"/></item></channel></rss>
Low
58
Humidity
66
Visibility
16.1

Using Temboo with older ARTIK Systems

A special Temboo library was preloaded on early ARTIK 520 and 1020 development boards running Fedora 20, for which a corresponding "ARTIK 10" selection was offered on the Temboo page. This selection will not work for any ARTIK boards running Fedora 22 or later, which includes all current boards.

The Arduino selection works on all board and firmware revisions (as long as the modifications explained above are made), and is therefore the only method currently supported.

Last updated on: