Pages: [1]   Go Down
Author Topic: error: invalid conversion from 'char' to 'const char*'  (Read 1065 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 67
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
// 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);
}
}
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 509
Posts: 31483
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 549
Posts: 46142
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 67
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Leeds, UK
Offline Offline
Edison Member
*
Karma: 72
Posts: 1641
Once the magic blue smoke is released, it won't go back in!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

(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:
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);
« Last Edit: March 03, 2013, 07:22:43 pm by Tom Carpenter » Logged

~Tom~

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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. smiley-wink
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 67
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Rome, Italy
Offline Offline
Sr. Member
****
Karma: 20
Posts: 442
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: [1]   Go Up
Jump to: