Black Lives Matter - Action and Equality. ... Adafruit is open and shipping.
0

How do I pull data from one feed and posting to another.
Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
Please be positive and constructive with your questions and comments.

How do I pull data from one feed and posting to another.

by rutledgek on Fri Jan 08, 2016 12:56 pm

I am adapting the Cloud based thermometer project and code so that it uses the Adafruit IO. I've been able to successfully send the current Temp to a feed in my IO titled "temperature". If the value post is successful, it will wait 60 seconds to post again, but if it is unsuccessful it will only wait 10 seconds and repeat.

The next part of the code I am trying to bring in is to check the latest value of a different IO Feed controlled by a slider on the dashboard. I want to set the desired temperature using the slider and use that as a variable to check against later in the code. I am stuck on how to bring in the latest value of that feed titled "Temperature Setting"

I am by no means a programmer, but I've been able to piece together the code I have.

Sorry, I posted this in the arduino forum, not realizing there was an IO forum. I hope to find some help.

I thought I could list a second feed in the setup. The first by itself works.

Code: Select all | TOGGLE FULL SIZE
Adafruit_IO_Feed testFeed = aio.getFeed("temperature");
Adafruit_IO_Feed settingFeed = aio.getFeed("Temperature Setting");


I only want to set up setPoint variable once per cooking session, so I included it in the setup. The notes are from the CC3000 sample.

Code: Select all | TOGGLE FULL SIZE
// Initialize the Adafruit IO client class (not strictly necessary with the
  // client class, but good practice).
  aio.begin();

  // Get the latest value of the temperature setting feed.
 
  FeedData setPoint = settingFeed.receive();
 
//print the value received from the feed
  if (setPoint.isValid()) {
    Serial.print(F("Received value from feed: ")); Serial.println(setPoint);
 // By default the received feed data item has a string value, however you
 // can use the following functions to attempt to convert it to a numeric
 // value like an int or float.  Each function returns a boolean that indicates
 // if the conversion succeeded, and takes as a parameter by reference the
 // output value.
    int i;
    if (setPoint.intValue(&i)) {
      Serial.print(F("Value as an int: ")); Serial.println(i, DEC);
    }
 // Other functions that you can use include:
 //  latest.uintValue() (unsigned int)
    //  latest.longValue() (long)
    //  latest.ulongValue() (unsigned long)
    //  latest.floatValue() (float)
    //  latest.doubleValue() (double)
  }
  else {
    Serial.print(F("Failed to receive the latest feed value!"));
  }
//print the variable setPoint to confirm it exists.
  Serial.println(F("Desired donness: ")); Serial.println(setPoint);
  Serial.println(F("Ready!"));


Am I pulling from two feeds incorrectly? Do I need to create two separate instances?

rutledgek
 
Posts: 17
Joined: Tue Jan 05, 2016 4:06 pm

Re: How do I pull data from one feed and posting to another.

by gbauer on Fri Jan 08, 2016 10:04 pm

Which part fails?

Is it on this line:
Code: Select all | TOGGLE FULL SIZE
Serial.println(F("Desired donness: ")); Serial.println(setPoint);


The Serial.println() may not know how to handle the setPoint, which has a type of FeedData.

Since you changed the setPoint to a integer, i, and Serial.println() knows what to do with that, you could change the statement to:
Code: Select all | TOGGLE FULL SIZE
Serial.println(F("Desired donness: ")); Serial.println(i);

gbauer
 
Posts: 10
Joined: Sun May 11, 2014 6:44 am

Re: How do I pull data from one feed and posting to another.

by rutledgek on Mon Jan 11, 2016 1:23 pm

Thanks for the reply.

In the serial monitor I get the desired text but no values.

Received value from feed:
Desired donness:

Since I am not getting an error message(Failed to receive last value). I am assuming the value is received, but not displayed. I used the line you gave, but in the verify it says that i was not declared in this scope.

rutledgek
 
Posts: 17
Joined: Tue Jan 05, 2016 4:06 pm

Re: How do I pull data from one feed and posting to another.

by pellico on Mon Jan 11, 2016 3:27 pm

because you having no understanding of programming, maybe look to see if there is something in Scratch or Snap4Arduino which will work with this. Those 2 things are graphical programming tools which might also help you learn how to program in programming languages like C, Java, etc.

BTW, the "i" in the example is a variable storing the integer which you would have to set from the read of your slider value.

pellico
 
Posts: 28
Joined: Thu Aug 15, 2013 6:20 pm

Re: How do I pull data from one feed and posting to another.

by gbauer on Tue Jan 12, 2016 9:10 pm

Hi rutledgek.
The problem occurs with the statement:
Code: Select all | TOGGLE FULL SIZE
Serial.println(setPoint);

As I wrote earlier, setPoint has a data type of FeedData and Serial.println does not know how to display that data type.

You need to convert the setPoint to the appropriate data type. The code has examples.
Code: Select all | TOGGLE FULL SIZE
// Other functions that you can use include:
//  latest.uintValue() (unsigned int)
//  latest.longValue() (long)
//  latest.ulongValue() (unsigned long)
//  latest.floatValue() (float)
//  latest.doubleValue() (double)


For example, you could do something like:

Code: Select all | TOGGLE FULL SIZE
float i; /* you have to declare the variable before you use it */
setPoint.floatValue(&i); /* get the float version of setPoint and assign it to variable i */
Serial.println(F("Desired donness: ")); Serial.println(i); /* print out your answer as a float */


good luck

gbauer
 
Posts: 10
Joined: Sun May 11, 2014 6:44 am

Please be positive and constructive with your questions and comments.