Dynamically Building a URL

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
shuntera
 
Posts: 2
Joined: Sun May 17, 2015 2:44 pm

Dynamically Building a URL

Post by shuntera »

Not sure why this is so much more difficult that it should be. But I am using the Adafruit_CC3000 library and buildtest example as the basis of my sketch to upload the value of my light sensor to thingspeak.

I am attempting to just get the following URL every couple of minutes:

http://api.thingspeak.com/update.json?a ... ld1=<value from light sensor>

So most of the URL is the same but on each iteration I need to append the value from the light sensor. I have tried the URL with dummy data in my web browser and it does work.

What I can't fathom is how to convert the analog value from the sensor into a string that I can then append to the end of the URL.

Here is what that part of the code looks like in the void loop

Code: Select all

void loop()
{
  int val = analogRead(sensePin);
  String fieldValue = String(val);
  
  Adafruit_CC3000_Client www = cc3000.connectTCP(ip, 80);
  if (www.connected()) {
    www.fastrprint(F("GET "));
    www.fastrprint(F("/update.json?api_key=<my_api_key>&field1="));
    www.fastrprint(fieldValue);
    www.fastrprint(F(" HTTP/1.1\r\n"));
    www.fastrprint(F("Host: ")); www.fastrprint(WEBSITE); www.fastrprint(F("\r\n"));
    www.fastrprint(F("\r\n"));
    www.println();
  } else {
    Serial.println(F("Connection failed"));
    return;
  }
This gives me the error : no known conversion for argument 1 from 'String' to 'const char*'

Can anyone give me a clue please how to tag this value on to the end of the URL?

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Dynamically Building a URL

Post by adafruit_support_rick »

There's no fastprint overload that takes a String object as an argument. So you have to convert the String object to a C string.
Try this:

Code: Select all

    www.fastrprint(fieldValue.c_str());

User avatar
shuntera
 
Posts: 2
Joined: Sun May 17, 2015 2:44 pm

Re: Dynamically Building a URL

Post by shuntera »

Thanks I will give that a try.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”