Arduino Polska Forum

Pełna wersja: Wywala błąd w kodzie.
Aktualnie przeglądasz uproszczoną wersję forum. Kliknij tutaj, by zobaczyć wersję z pełnym formatowaniem.
Witam, mam taki kod (kawałek), w którym wywala błąd, tak jak poniżej, co może być nie tak?
Kod:
if (!ether.dnsLookup(website)) // W tej lini wywala błąd
Kod:
void setup () {
Serial.begin(57600);
Serial.println("\n[webClient]");

if (ether.begin(sizeof Ethernet::buffer, mymac) == 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);  

if (!ether.dnsLookup(website))
  Serial.println("DNS failed");
 
ether.printIp("SRV: ", ether.hisip);
}

Błąd:
sketch_mar20b.ino: In function 'void setup()':
sketch_mar20b:43: error: invalid conversion from 'const char*' to 'prog_char*'
sketch_mar20b:43: error: initializing argument 1 of 'static bool EtherCard::dnsLookup(prog_char*, bool)'
sketch_mar20b.ino: In function 'void loop()':
sketch_mar20b:60: error: call of overloaded 'String(float, int)' is ambiguous
C:\Users\Kuba\Desktop\arduino-1.0.5-r2-windows\arduino-1.0.5-r2\hardware\arduino\cores\arduino/WString.h:70: note: candidates are: String::String(long unsigned int, unsigned char)
C:\Users\Kuba\Desktop\arduino-1.0.5-r2-windows\arduino-1.0.5-r2\hardware\arduino\cores\arduino/WString.h:69: note: String::String(long int, unsigned char)
C:\Users\Kuba\Desktop\arduino-1.0.5-r2-windows\arduino-1.0.5-r2\hardware\arduino\cores\arduino/WString.h:68: note: String::String(unsigned int, unsigned char)
C:\Users\Kuba\Desktop\arduino-1.0.5-r2-windows\arduino-1.0.5-r2\hardware\arduino\cores\arduino/WString.h:67: note: String::String(int, unsigned char)
C:\Users\Kuba\Desktop\arduino-1.0.5-r2-windows\arduino-1.0.5-r2\hardware\arduino\cores\arduino/WString.h:66: note: String::String(unsigned char, unsigned char)
sketch_mar20b:62: error: call of overloaded 'String(float, int)' is ambiguous
C:\Users\Kuba\Desktop\arduino-1.0.5-r2-windows\arduino-1.0.5-r2\hardware\arduino\cores\arduino/WString.h:70: note: candidates are: String::String(long unsigned int, unsigned char)
C:\Users\Kuba\Desktop\arduino-1.0.5-r2-windows\arduino-1.0.5-r2\hardware\arduino\cores\arduino/WString.h:69: note: String::String(long int, unsigned char)
C:\Users\Kuba\Desktop\arduino-1.0.5-r2-windows\arduino-1.0.5-r2\hardware\arduino\cores\arduino/WString.h:68: note: String::String(unsigned int, unsigned char)
C:\Users\Kuba\Desktop\arduino-1.0.5-r2-windows\arduino-1.0.5-r2\hardware\arduino\cores\arduino/WString.h:67: note: String::String(int, unsigned char)
C:\Users\Kuba\Desktop\arduino-1.0.5-r2-windows\arduino-1.0.5-r2\hardware\arduino\cores\arduino/WString.h:66: note: String::String(unsigned char, unsigned char)

Dziękuje, Pozdrawiam Wink
Błąd masz już tu:
Cytat:sketch_mar20b:43: error: invalid conversion from 'const char*' to 'prog_char*'
sketch_mar20b:43: error: initializing argument 1 of 'static bool EtherCard::dnsLookup(prog_char*, bool)'

Zamieść cały program i link do biblioteki.
Dlaczego używasz tak starej wersji oprogramowania(1.0.5)?
Tak starej wersji oprogramowania używam ponieważ na nowszej nie chciały mi działać niektóre rzeczy. Wink



Kod:
#include <EtherCard.h>
#include <OneWire.h>


int DS18S20_Pin = 5;
OneWire ds(DS18S20_Pin);

static uint8_t mymac[6] = {
 0x54, 0x55, 0x58, 0x10, 0x00, 0x24};                  
static uint8_t ip[4] = {
 192, 168, 0, 185};          
static uint16_t port = 80;
byte Ethernet::buffer[700];
static uint32_t timer;
const char website[] PROGMEM = "api.thingspeak.com";
// 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(F("\n[webClient]"));
if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
Serial.println(F("Failed to access Ethernet controller"));
if (!ether.dhcpSetup())
Serial.println(F("DHCP failed"));
ether.printIp("IP: ", ether.myip);
ether.printIp("GW: ", ether.gwip);
ether.printIp("DNS: ", ether.dnsip);
if (!ether.dnsLookup(website))
Serial.println("DNS failed");
ether.printIp("SRV: ", ether.hisip);
}
void loop () {
 float temperature = getTemp();
ether.packetLoop(ether.packetReceive());
if (millis() > timer) {
timer = millis() + 5000;
Serial.println();
Serial.print("<<< REQ ");
Serial.print(temperature);
int myInt = temperature;  
char myIntAsString[7];
itoa(myInt, myIntAsString, 10);
ether.browseUrl(PSTR("/update?key=1234678&field1="), myIntAsString, website, my_callback);

}
}

float getTemp(){
//returns the temperature from one DS18S20 in DEG Celsius

byte data[12];
byte addr[8];

if ( !ds.search(addr)) {
//no more sensors on chain, reset search
ds.reset_search();
return -1000;
}

if ( OneWire::crc8( addr, 5 ) != addr[5]) {
Serial.println("CRC is not valid!");
return -1000;
}

if ( addr[0] != 0x10 && addr[0] != 0x28) {
Serial.print("Device is not recognized");
return -1000;
}

ds.reset();
ds.select(addr);
ds.write(0x44,1); // start conversion, with parasite power on at the end

byte present = ds.reset();
ds.select(addr);
ds.write(0xBE); // Read Scratchpad


for (int i = 0; i < 9; i++) { // we need 9 bytes
data[i] = ds.read();
}

ds.reset_search();

byte MSB = data[1];
byte LSB = data[0];

float tempRead = ((MSB << 8) | LSB); //using two's compliment
float TemperatureSum = tempRead / 16;

return TemperatureSum;

}

Powiedzmy taki kod.
Na wersji 1.8.1 kompilacja przeszła pomyślnie. Być może jest to kwestia biblioteki(miałeś podać źródło swojej).
Sprawdzałem na 1.8.1 i nie działa, to biblioteka inna.

Moja biblioteka: https://github.com/jcw/ethercard
Już działa. Wink
(21-03-2017, 16:19)Kubaa napisał(a): [ -> ]Już działa. Wink
Super.
Ponieważ forum nie jest tylko dla Ciebie a dla wszystkich, to napisz w jakiej konfiguracji działa - wersja IDE, biblioteka.
Ide 1.8.1, usunąłem wszystkie biblioteki dot. EtherCard i wgrałem od nowa tą co poprzednio.