Go Down

Topic: error: invalid conversion from 'char' to 'const char*' (Read 2235 times) previous topic - next topic

smallpoul

Hi all,

        My problem is i want to put a variable for the temperature but i have an error: error: invalid conversion from 'char' to 'const char'
here the code:

Code: [Select]
// Demo using DHCP and DNS to perform a web client request.
// 2011-06-08 <jc@wippler.nl> http://opensource.org/licenses/mit-license.php

#include <EtherCard.h>

// ethernet interface mac address, must be unique on the LAN
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };

byte Ethernet::buffer[700];
static uint32_t timer;

char website[] PROGMEM = "192.168.2.19";
static byte hisip[] = {192,168,2,19};
char temperature;

// called when the client request is complete
static void my_callback (byte status, word off, word len) {
  Serial.println(">>>");
  Ethernet::buffer[off+300] = 0;
  Serial.print((const char*) Ethernet::buffer + off);
  Serial.println("...");
}

void setup () {
  Serial.begin(57600);
  Serial.println("\n[webClient]");

  if (ether.begin(sizeof Ethernet::buffer, mymac, 10) == 0)
    Serial.println( "Failed to access Ethernet controller");
  if (!ether.dhcpSetup())
    Serial.println("DHCP failed");

  ether.printIp("IP:  ", ether.myip);
  ether.printIp("GW:  ", ether.gwip); 
  ether.printIp("DNS: ", ether.dnsip); 
  ether.copyIp(ether.hisip, hisip);
  ether.hisport = 3480;
  ether.printIp("SRV: ", ether.hisip);

  if (!ether.dnsLookup(website))
    Serial.println("DNS failed");
}

void loop () {
  ether.packetLoop(ether.packetReceive());
 
  if (millis() > timer) {
    timer = millis() + 10000;
    temperature = 77;
    Serial.println();
    Serial.print("<<< REQ ");
    ether.browseUrl(PSTR("/data_request?id=variableset&DeviceNum=49&serviceId=urn:upnp-org:serviceId:TemperatureSensor1&Variable=CurrentTemperature&Value="), temperature, website, my_callback);
}
}


Grumpy_Mike

You have defined your temprature variable as a char, this is use for single ASCII symbols so it is the wrong thing to use. It needs to be an int or a float.

PaulS

Quote
but i have an error: error: invalid conversion from 'char' to 'const char'

The error message provided more information than that. Specifically, it told you what line number the error was on.

Why is temperature a char? It rarely gets to 'H' degrees here.

smallpoul

Try with int and float, same problem, ethercard seems to need a const char* in the formule: ether.browseUrl(PSTR.....
How could i declare a const char* that could be variable.

Thanks in advance

Tom Carpenter

#4
Mar 04, 2013, 01:09 am Last Edit: Mar 04, 2013, 01:22 am by Tom Carpenter Reason: 1
(1) @PaulS and @Grumpy_Mike... why not declare temperature as a char? Last time I checked, the temperature around here is unlikely to get above 127 degrees C or less than -128 degrees C. What on earth is the point in using an int when you don't need two bytes to store the value, you are just wasting a byte of precious RAM. Remeber folks, just because a char is called a char doesn't mean it has to be used to store a character! (Oh, and the temperature could be 'H', that would be room temperature if it were in fahrenheit: 72 degrees F is approx. 22 degrees C)

(2) The issue lies in this line:
ether.browseUrl(PSTR("/data_request?id=variableset&DeviceNum=49&serviceId=urn:upnp-org:serviceId:TemperatureSensor1&Variable=CurrentTemperature&Value="), temperature, website, my_callback);

You first need to convert the temperature to a string of characters before passing it to that function. For example:

Code: [Select]
char temp[5];
sprintf(temp,"%d",temperature);
ether.browseUrl(PSTR("/data_request?id=variableset&DeviceNum=49&serviceId=urn:upnp-org:serviceId:TemperatureSensor1&Variable=CurrentTemperature&Value="), temp, website, my_callback);
~Tom~

Nick Gammon


Last time I checked, the temperature around here is unlikely to get above 127 degrees C and less than -128 degrees C.


Don't forget Global Warming, Tom. ;)
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

smallpoul

Thanks,
           i try what you say and now i'm able to compile it without error.
The problem now is that it give me a bad request. If i print the temp, it give me the temperature. If i replace the temp with "88", no error occur and value 88 is updated. I'm lost

spatula


Thanks,
           i try what you say and now i'm able to compile it without error.
The problem now is that it give me a bad request. If i print the temp, it give me the temperature. If i replace the temp with "88", no error occur and value 88 is updated. I'm lost


This is a test for a missing control in your receiving, server-side code. 88 is an unusual, but valid value. In normal conditions the sensor would not return such a value, but if you "force" it into the query request there's nothing the Arduino can do; you need to provide a value-checking routine in your server code.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy