Go Down

Topic: ThingSpeak Client to Connect Arduino to the Internet (Read 20900 times) previous topic - next topic

rpurser

Hi all,

Version 1.1.0 of the libraries Has mentions now supports ESP8226 devices, the Particle Electron (coming soon!).

You can use these libraries directly from within the Arduino and Particle IDEs.

All the best,
-Rob
Visit www.mathworks.com/iot to learn more about analyzing your IoT data.  Visit www.funwitharduino.net to learn more about my intro and intermediate arduino courses.

TipsEZ

So I'm a big time newb to the IoT world and HTTP. I'm trying to read my status on Thingspeak using an ESP8266 running Arduino. I've edited one of the examples to try to do what I want, but I don't seem to have things right. I've also tried sending my tweet as a string to a field on Thingspeak so that I could use the built in "readField" command(s). Any help is greatly appreciated. I'm running road block after roadblock here.

Code: [Select]

#include "ThingSpeak.h"

#ifdef ARDUINO_ARCH_ESP8266
  #include <ESP8266WiFi.h>
    char ssid[] = "<Work Sucks, Quit Now>";          //  your network SSID (name)
    char pass[] = "<Seriously Quit Now>";            // your network password
  int status = WL_IDLE_STATUS;
  WiFiClient  client;
#endif

long myChannelNumber = 78204;
const char * myReadAPIKey = "HP5KTQQFBRTT7FRU";

void setup() {
  #if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_ESP8266)
    Serial.begin(115200);
    #ifdef ARDUINO_AVR_YUN
      Bridge.begin();
    #else
      #if defined(USE_WIFI_SHIELD) || defined(ARDUINO_ARCH_ESP8266)
        WiFi.begin(ssid, pass);
      #else
        Ethernet.begin(mac);
      #endif
    #endif
  #endif

  ThingSpeak.begin(client);
}

void loop() {
  // Read the latest value from field 1 of channel 31461
 client.print("GET http://api.thingspeak.com/channels/78204/status.json?api_key=SSE5518BZGNQ538K");
 delay (10);
 String Tweet = client.read();
 // String sTweet = ThingSpeak.readStringField(myChannelNumber,2);
 //String sTweet = Tweet;
  int nField1 = ThingSpeak.readIntField(myChannelNumber, 1);
  int nField2 = ThingSpeak.readIntField(myChannelNumber, 2);
 
  #if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_ESP8266)
    Serial.print("Latest tweet is: ");
    Serial.print(Tweet);
    //Serial.print(sTweet);
    Serial.print (nField1);
    Serial.print (nField2);
    Serial.println(" , holy crap it worked!");
   //sTweet = client.print("GET api.thingspeak.com/apps/thinghttp/send_request?api_key=SSE5518BZGNQ538K");
   Serial.println(Tweet);
   
  #endif
  delay(30000);
}

rpurser

Hi TipsEZ,

Love to help.   Just a note -- it's best if you hide your API keys when you post, or anyone can access your private channel.

The ThingSpeak library is designed to hide all the HTTP stuff from you. 

I can't quite figure out what your goal is from the code you've posted.  If you want to read a string from a provate channel from ThingSpeak, check out the ReadPrivateChannel example.  Try getting that to work first without any changes.  Then switch it to read your channel.  Since it looks like your channel has a text string in it, you'll need to change to the readStringField method.

You may find this ThingSpeak video helpful: http://www.mathworks.com/videos/introduction-to-thingspeak-107749.html

-Rob
Visit www.mathworks.com/iot to learn more about analyzing your IoT data.  Visit www.funwitharduino.net to learn more about my intro and intermediate arduino courses.

TipsEZ

Thank you for your reply. What I am trying to do is send a tweet from my phone, that activitates a stepper motor ran from an Adafruit Huzzah (ESP8266). So I have my thing speak set up currently, per examples, so that when I Tweet something like "TweetControl, #FlagsHalfStaff" it posts this tweet as a status update on my Thingspeak page. When I try to do a "GET" from Thingspeak I get nothing back.

I'd really like to parse my Tweet, similiar to the example, so that anything after the # sign is dropped into Field 2 as a string, then simply use the "readStringField(myChannel, 2)" command.

DBBEN

Hi! I would like to ask if this would work on ESP8266 Wifi Module.

rpurser

Yes.  The latest version (1.1.1) works with esp8266 devices.  I tested it with a SparkFun Dev board.

Good luck!

-Rob
Visit www.mathworks.com/iot to learn more about analyzing your IoT data.  Visit www.funwitharduino.net to learn more about my intro and intermediate arduino courses.

SAII

I am facing same issue. I checked above code but its displaying 72 as received data which is wrong data.

So, can any one help me out for solving issue or we can't read back data from thingspeak.

rpurser

Hi -- post some code and let us know what device you're using...  Make sure you hide your API key.   Are you getting a success/failure code?  Do the demos work?

-Rob
Visit www.mathworks.com/iot to learn more about analyzing your IoT data.  Visit www.funwitharduino.net to learn more about my intro and intermediate arduino courses.

Go Up