Problemen met code,s en fouten

IDE gerelateerde berichten
Berichten: 13
Geregistreerd: 11 Jan 2015, 16:25

Problemen met code,s en fouten

Berichtdoor weske2000 » 11 Jan 2015, 16:39

Ik wil graag een ds18 met webserver gebruiken maar krijg de code niet werkend
steeds fouten ik heb een ethernet shield met een enc28j60 chip.
Heeft iemand een goede lib met een ds18 en een webserver die werkt met enc28j60 ?

Deze code als voorbeeld

#include "etherShield.h"

// please modify the following two lines. mac and ip have to be unique
// in your local area network. You can not have the same numbers in
// two devices:
static uint8_t mymac[6] = {0x54,0x55,0x58,0x10,0x00,0x24};
static uint8_t myip[4] = {192,168,1,15};
static char baseurl[]="http://192.168.1.15/";
static uint16_t mywwwport =80; // listen port for tcp/www (max range 1-254)
// or on a different port:
//static char baseurl[]="http://10.0.0.24:88/";
//static uint16_t mywwwport =88; // listen port for tcp/www (max range 1-254)
//


#define BUFFER_SIZE 500
static uint8_t buf[BUFFER_SIZE+1];
#define STR_BUFFER_SIZE 22
static char strbuf[STR_BUFFER_SIZE+1];

EtherShield es=EtherShield();

// prepare the webpage by writing the data to the tcp send buffer
uint16_t print_webpage(uint8_t *buf);
int8_t analyse_cmd(char *str);
// get current temperature
#define TEMP_PIN 3
void getCurrentTemp( int *sign, int *whole, int *fract);

void setup(){

/*initialize enc28j60*/
es.ES_enc28j60Init(mymac);
es.ES_enc28j60clkout(2); // change clkout from 6.25MHz to 12.5MHz
delay(10);

/* Magjack leds configuration, see enc28j60 datasheet, page 11 */
// LEDA=greed LEDB=yellow
//
// 0x880 is PHLCON LEDB=on, LEDA=on
// enc28j60PhyWrite(PHLCON,0b0000 1000 1000 00 00);
es.ES_enc28j60PhyWrite(PHLCON,0x880);
delay(500);
//
// 0x990 is PHLCON LEDB=off, LEDA=off
// enc28j60PhyWrite(PHLCON,0b0000 1001 1001 00 00);
es.ES_enc28j60PhyWrite(PHLCON,0x990);
delay(500);
//
// 0x880 is PHLCON LEDB=on, LEDA=on
// enc28j60PhyWrite(PHLCON,0b0000 1000 1000 00 00);
es.ES_enc28j60PhyWrite(PHLCON,0x880);
delay(500);
//
// 0x990 is PHLCON LEDB=off, LEDA=off
// enc28j60PhyWrite(PHLCON,0b0000 1001 1001 00 00);
es.ES_enc28j60PhyWrite(PHLCON,0x990);
delay(500);
//
// 0x476 is PHLCON LEDA=links status, LEDB=receive/transmit
// enc28j60PhyWrite(PHLCON,0b0000 0100 0111 01 10);
es.ES_enc28j60PhyWrite(PHLCON,0x476);
delay(100);

//init the ethernet/ip layer:
es.ES_init_ip_arp_udp_tcp(mymac,myip,80);

// initialize DS18B20 datapin
digitalWrite(TEMP_PIN, LOW);
pinMode(TEMP_PIN, INPUT); // sets the digital pin as input (logic 1)


}

void loop(){
uint16_t plen, dat_p;
int8_t cmd;

plen = es.ES_enc28j60PacketReceive(BUFFER_SIZE, buf);

/*plen will ne unequal to zero if there is a valid packet (without crc error) */
if(plen!=0){

// arp is broadcast if unknown but a host may also verify the mac address by sending it to a unicast address.
if(es.ES_eth_type_is_arp_and_my_ip(buf,plen)){
es.ES_make_arp_answer_from_request(buf);
return;
}

// check if ip packets are for us:
if(es.ES_eth_type_is_ip_and_my_ip(buf,plen)==0){
return;
}

if(buf[IP_PROTO_P]==IP_PROTO_ICMP_V && buf[ICMP_TYPE_P]==ICMP_TYPE_ECHOREQUEST_V){
es.ES_make_echo_reply_from_request(buf,plen);
return;
}

// tcp port www start, compare only the lower byte
if (buf[IP_PROTO_P]==IP_PROTO_TCP_V&&buf[TCP_DST_PORT_H_P]==0&&buf[TCP_DST_PORT_L_P]==mywwwport){
if (buf[TCP_FLAGS_P] & TCP_FLAGS_SYN_V){
es.ES_make_tcp_synack_from_syn(buf); // make_tcp_synack_from_syn does already send the syn,ack
return;
}
if (buf[TCP_FLAGS_P] & TCP_FLAGS_ACK_V){
es.ES_init_len_info(buf); // init some data structures
dat_p=es.ES_get_tcp_data_pointer();
if (dat_p==0){ // we can possibly have no data, just ack:
if (buf[TCP_FLAGS_P] & TCP_FLAGS_FIN_V){
es.ES_make_tcp_ack_from_any(buf);
}
return;
}
if (strncmp("GET ",(char *)&(buf[dat_p]),4)!=0){
// head, post and other methods for possible status codes see:
// http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
plen=es.ES_fill_tcp_data_p(buf,0,PSTR("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n<h1>200 OK</h1>"));
goto SENDTCP;
}
if (strncmp("/ ",(char *)&(buf[dat_p+4]),2)==0){
plen=print_webpage(buf);
goto SENDTCP;
}
cmd=analyse_cmd((char *)&(buf[dat_p+5]));
if (cmd==1){
plen=print_webpage(buf);
}
SENDTCP: es.ES_make_tcp_ack_from_any(buf); // send ack for http get
es.ES_make_tcp_ack_with_data(buf,plen); // send data
}
}
}

}
// The returned value is stored in the global var strbuf
uint8_t find_key_val(char *str,char *key)
{
uint8_t found=0;
uint8_t i=0;
char *kp;
kp=key;
while(*str && *str!=' ' && found==0){
if (*str == *kp){
kp++;
if (*kp == '\0'){
str++;
kp=key;
if (*str == '='){
found=1;
}
}
}else{
kp=key;
}
str++;
}
if (found==1){
// copy the value to a buffer and terminate it with '\0'
while(*str && *str!=' ' && *str!='&' && i<STR_BUFFER_SIZE){
strbuf[i]=*str;
i++;
str++;
}
strbuf[i]='\0';
}
return(found);
}

int8_t analyse_cmd(char *str)
{
int8_t r=-1;

if (find_key_val(str,"cmd")){
if (*strbuf < 0x3a && *strbuf > 0x2f){
// is a ASCII number, return it
r=(*strbuf-0x30);
}
}
return r;
}


uint16_t print_webpage(uint8_t *buf)
{
char temp_string[10];
int i=0;
//char *temp_string="100";

uint16_t plen;

getCurrentTemp(temp_string);

plen=es.ES_fill_tcp_data_p(buf,0,PSTR("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n"));
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<center><p><h1>Welcome to Arduino Ethernet Shield V1.0 </h1></p> "));

plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<hr><br><form METHOD=get action=\""));
plen=es.ES_fill_tcp_data(buf,plen,baseurl);
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("\">"));
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<h2> Current Temperature is </h2> "));
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<h1><font color=\"#00FF00\"> "));


while (temp_string[i]) {
buf[TCP_CHECKSUM_L_P+3+plen]=temp_string[i++];
plen++;
}

plen=es.ES_fill_tcp_data_p(buf,plen,PSTR(" &#176C</font></h1><br> ") );
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=hidden name=cmd value=1>"));
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=submit value=\"Get Temperature\"></form>"));
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("</center><hr> <p> V1.0 <a href=\"http://www.nuelectronics.com\">www.nuelectronics.com<a>"));

return(plen);
}


void OneWireReset(int Pin) // reset. Should improve to act as a presence pulse
{
digitalWrite(Pin, LOW);
pinMode(Pin, OUTPUT); // bring low for 500 us
delayMicroseconds(500);
pinMode(Pin, INPUT);
delayMicroseconds(500);
}

void OneWireOutByte(int Pin, byte d) // output byte d (least sig bit first).
{
byte n;

for(n=8; n!=0; n--)
{
if ((d & 0x01) == 1) // test least sig bit
{
digitalWrite(Pin, LOW);
pinMode(Pin, OUTPUT);
delayMicroseconds(5);
pinMode(Pin, INPUT);
delayMicroseconds(60);
}
else
{
digitalWrite(Pin, LOW);
pinMode(Pin, OUTPUT);
delayMicroseconds(60);
pinMode(Pin, INPUT);
}

d=d>>1; // now the next bit is in the least sig bit position.
}

}

byte OneWireInByte(int Pin) // read byte, least sig byte first
{
byte d, n, b;

for (n=0; n<8; n++)
{
digitalWrite(Pin, LOW);
pinMode(Pin, OUTPUT);
delayMicroseconds(5);
pinMode(Pin, INPUT);
delayMicroseconds(5);
b = digitalRead(Pin);
delayMicroseconds(50);
d = (d >> 1) | (b<<7); // shift d to right and insert b in most sig bit position
}
return(d);
}


void getCurrentTemp(char *temp)
{
int HighByte, LowByte, TReading, Tc_100, sign, whole, fract;

OneWireReset(TEMP_PIN);
OneWireOutByte(TEMP_PIN, 0xcc);
OneWireOutByte(TEMP_PIN, 0x44); // perform temperature conversion, strong pullup for one sec

OneWireReset(TEMP_PIN);
OneWireOutByte(TEMP_PIN, 0xcc);
OneWireOutByte(TEMP_PIN, 0xbe);

LowByte = OneWireInByte(TEMP_PIN);
HighByte = OneWireInByte(TEMP_PIN);
TReading = (HighByte << 8) + LowByte;
sign = TReading & 0x8000; // test most sig bit
if (sign) // negative
{
TReading = (TReading ^ 0xffff) + 1; // 2's comp
}
Tc_100 = (6 * TReading) + TReading / 4; // multiply by (100 * 0.0625) or 6.25

whole = Tc_100 / 100; // separate off the whole and fractional portions
fract = Tc_100 % 100;


if(sign) temp[0]='-';
else temp[0]='+';

if(whole/100==0)
temp[1] =' ';
else
temp[1]= whole/100+'0';
temp[2]= (whole-(whole/100)*100)/10 +'0' ;
temp[3]= whole-(whole/10)*10 +'0';

temp[4]='.';
temp[5]=fract/10 +'0';
temp[6]=fract-(fract/10)*10 +'0';

temp[7] = '\0';



}



==================================================

Met de onderste foutcodes

C:\Documents and Settings\Administrator\Mijn documenten\Arduino\libraries\etherShield\EthernetClient.cpp:1:19: error: w5200.h: No such file or directory
C:\Documents and Settings\Administrator\Mijn documenten\Arduino\libraries\etherShield\EthernetClient.cpp:2:20: error: socket.h: No such file or directory
C:\Documents and Settings\Administrator\Mijn documenten\Arduino\libraries\etherShield\EthernetClient.cpp:10:22: error: Ethernet.h: No such file or directory
C:\Documents and Settings\Administrator\Mijn documenten\Arduino\libraries\etherShield\EthernetClient.cpp:11:28: error: EthernetClient.h: No such file or directory
C:\Documents and Settings\Administrator\Mijn documenten\Arduino\libraries\etherShield\EthernetClient.cpp:12:28: error: EthernetServer.h: No such file or directory
C:\Documents and Settings\Administrator\Mijn documenten\Arduino\libraries\etherShield\EthernetClient.cpp:13:17: error: Dns.h: No such file or directory
C:\Documents and Settings\Administrator\Mijn documenten\Arduino\libraries\etherShield\EthernetClient.cpp:14:23: error: KMPCommon.h: No such file or directory
C:\Documents and Settings\Administrator\Mijn documenten\Arduino\libraries\etherShield\EthernetClient.cpp:16: error: 'EthernetClient' has not been declared
C:\Documents and Settings\Administrator\Mijn documenten\Arduino\libraries\etherShield\EthernetClient.cpp:18: error: 'EthernetClient' has not been declared
C:\Documents and Settings\Administrator\Mijn documenten\Arduino\libraries\etherShield\EthernetClient.cpp:18: error: ISO C++ forbids declaration of 'EthernetClient' with no type
C:\Documents and Settings\Administrator\Mijn documenten\Arduino\libraries\etherShield\EthernetClient.cpp: In function 'int EthernetClient()':
C:\Documents and Settings\Administrator\Mijn documenten\Arduino\libraries\etherShield\EthernetClient.cpp:18: error: only constructors take base initializers
C:\Documents and Settings\Administrator\Mijn documenten\Arduino\libraries\etherShield\EthernetClient.cpp:18: error: 'MAX_SOCK_NUM' was not declared in this scope
C:\Documents and Settings\Administrator\Mijn documenten\Arduino\libraries\etherShield\EthernetClient.cpp: At global scope:
C:\Documents and Settings\Administrator\Mijn documenten\Arduino\libraries\etherShield\EthernetClient.cpp:22: error: 'EthernetClient' is not a class or namespace
C:\Documents and Settings\Administrator\Mijn documenten\Arduino\libraries\etherShield\EthernetClient.cpp:22: error: ISO C++ forbids declaration of 'EthernetClient' with no type
C:\Documents and Settings\Administrator\Mijn documenten\Arduino\libraries\etherShield\EthernetClient.cpp: In function 'int EthernetClient(uint8_t)':
C:\Documents and Settings\Administrator\Mijn documenten\Arduino\libraries\etherShield\EthernetClient.cpp:22: error: only constructors take base initializers
C:\Documents and Settings\Administrator\Mijn documenten\Arduino\libraries\etherShield\EthernetClient.cpp: At global scope:
C:\Documents and Settings\Administrator\Mijn documenten\Arduino\libraries\etherShield\EthernetClient.cpp:26: error: 'EthernetClient' is not a class or namespace
C:\Documents and Settings\Administrator\Mijn documenten\Arduino\libraries\etherShield\EthernetClient.cpp: In function 'int connect(const char*, uint16_t)':
C:\Documents and Settings\Administrator\Mijn documenten\Arduino\libraries\etherShield\EthernetClient.cpp:29: error: 'DNSClient' was not declared in this scope
C:\Documents and Settings\Administrator\Mijn documenten\Arduino\libraries\etherShield\EthernetClient.cpp:29: error: expected `;' before 'dns'
C:\Documents and Settings\Administrator\Mijn documenten\Arduino\libraries\etherShield\EthernetClient.cpp:30: error: 'IPAddress' was not declared in this scope
C:\Documents and Settings\Administrator\Mijn documenten\Arduino\libraries\etherShield\EthernetClient.cpp:30: error: expected `;' before 'remote_addr'
C:\Documents and Settings\Administrator\Mijn documenten\Arduino\libraries\etherShield\EthernetClient.cpp:32: error: 'dns' was not declared in this scope
C:\Documents and Settings\Administrator\Mijn documenten\Arduino\libraries\etherShield\EthernetClient.cpp:32: error: 'Ethernet' was not declared in this scope
C:\Documents and Settings\Administrator\Mijn documenten\Arduino\libraries\etherShield\EthernetClient.cpp:33: error: 'remote_addr' was not declared in this scope
C:\Documents and Settings\Administrator\Mijn documenten\Arduino\libraries\etherShield\EthernetClient.cpp: At global scope:
C:\Documents and Settings\Administrator\Mijn documenten\Arduino\libraries\etherShield\EthernetClient.cpp:41: error: 'EthernetClient' is not a class or namespace
C:\Documents and Settings\Administrator\Mijn documenten\Arduino\libraries\etherShield\EthernetClient.cpp:41: error: 'int connect' redeclared as different kind of symbol
C:\Documents and Settings\Administrator\Mijn documenten\Arduino\libraries\etherShield\EthernetClient.cpp:26: error: previous declaration of 'int connect(const char*, uint16_t)'
C:\Documents and Settings\Administrator\Mijn documenten\Arduino\libraries\etherShield\EthernetClient.cpp:41: error: 'IPAddress' was not declared in this scope
C:\Documents and Settings\Administrator\Mijn documenten\Arduino\libraries\etherShield\EthernetClient.cpp:41: error: expected primary-expression before 'port'


----------------------------------------------------------------------------------------------


Alvast vriendelijk dank

Advertisement

Gebruikers-avatar
Berichten: 5043
Geregistreerd: 13 Mei 2013, 20:57
Woonplaats: Heemskerk

Re: Problemen met code,s en fouten

Berichtdoor nicoverduin » 11 Jan 2015, 17:33

heb je al gegoogled?
Docent HBO Technische Informatica, Embedded ontwikkelaar & elektronicus
http://www.verelec.nl

Berichten: 13
Geregistreerd: 11 Jan 2015, 16:25

Re: Problemen met code,s en fouten

Berichtdoor weske2000 » 11 Jan 2015, 17:42

Ja heb ik al eindeloos gedaan ben ook al genoeg tegen gekomen .
Maar als ik die lib gebruik loop ik steeds tegen fouten aan ook als ik werkende codes kopieer van het net.
Ik weet niet wat ik fout doe wil ook graag van deze site de code gebruiken

http://www.allmycircuits.io/?app=etherino

Krijg deze fouten


sketch_jan12a:22: error: variable or field 'process' declared void
sketch_jan12a:22: error: 'EthernetClient' was not declared in this scope
sketch_jan12a:23: error: variable or field 'digitalCommand' declared void
sketch_jan12a:23: error: 'EthernetClient' was not declared in this scope
sketch_jan12a:24: error: variable or field 'analogCommand' declared void
sketch_jan12a:24: error: 'EthernetClient' was not declared in this scope
sketch_jan12a:25: error: variable or field 'modeCommand' declared void
sketch_jan12a:25: error: 'EthernetClient' was not declared in this scope
sketch_jan12a:40: error: 'EthernetServer' does not name a type
sketch_jan12a.cpp: In function 'void setup()':
sketch_jan12a:58: error: 'Ethernet' was not declared in this scope
sketch_jan12a:60: error: 'server' was not declared in this scope
sketch_jan12a.cpp: In function 'void loop()':
sketch_jan12a:72: error: 'EthernetClient' was not declared in this scope
sketch_jan12a:72: error: expected `;' before 'client'
sketch_jan12a:76: error: 'client' was not declared in this scope
sketch_jan12a:80: error: 'process' was not declared in this scope
sketch_jan12a.cpp: At global scope:
sketch_jan12a:92: error: variable or field 'process' declared void
sketch_jan12a:92: error: 'EthernetClient' was not declared in this scope

Graag wat hulp

vriendelijk dank

Gebruikers-avatar
Berichten: 5043
Geregistreerd: 13 Mei 2013, 20:57
Woonplaats: Heemskerk

Re: Problemen met code,s en fouten

Berichtdoor nicoverduin » 11 Jan 2015, 18:41

Je moet natuurlijk wel de juiste library voor de juiste chip gebruiken. En als je googled vind je voldoende libraries voor deze chip. Ik vroeg het niet voor niets. Jij hebt geen ethernet shield want daar zit een WS5100 of WS5200 chip op. Daarnaast moet je geïmporteerde libraries in {jouw sketch folder/libraries zetten. En dat is NIET de in de hardware folder. Mocht je die daar wel neergezet hebben kun je die beter gelijk daar vandaan verwijderen.
Verder is er uitgebreide informatie over het installeren van libraries http://arduino.cc/en/pmwiki.php?n=Guide/Libraries

@edit: En als je ff googled op "enc28j60 arduino example"

Heb je hem gelijk bovenaan staan.........
Docent HBO Technische Informatica, Embedded ontwikkelaar & elektronicus
http://www.verelec.nl

Berichten: 13
Geregistreerd: 11 Jan 2015, 16:25

Re: Problemen met code,s en fouten

Berichtdoor weske2000 » 11 Jan 2015, 19:14

Beste Nico bedankt voor je tips

Ik kan dus niet zomaar codes van internet gebruiken als ik de libs niet heb.?

Ik snap niet helemaal wat ik fout doe met die files op de juiste plaats te zetten .

En hoe moet ik dan mijn ds18 waardes online zetten snap het niet ben nu al 2 weken bezig :( .

Kunt u me evt nog wat helpen

Alvast vriendelijk dank mvg wesley

Gebruikers-avatar
Berichten: 5043
Geregistreerd: 13 Mei 2013, 20:57
Woonplaats: Heemskerk

Re: Problemen met code,s en fouten

Berichtdoor nicoverduin » 11 Jan 2015, 20:33

Wesley
a) De Arduino IDE moet je gewoon installeren volgens de instructies. En daarna moet je er in feite met je vingers vanaf blijven
b) Als je de Arduino IDE opstart kun je via Bestand->Voorkeuren aangeven waar jouw sketches op geslagen moeten worden. Als het er al niet staat, is "Mijn Documenten/Arduino" de handigste plek
c) In diezelfde folder staat er daarna een folder "libraries" En zo niet dan moet je die maken. In deze folder zet je voortaan ALLE gedownloade libraries
De Arduino IDE wordt standaard geleverd met een aantal hardware en software libraries. In principe heb je daar verder niets te zoeken. Echter er worden elke dag weer libraries gemaakt die beschikbaar komen voor iedereen. Om die te kunnen gebruiken moet je ze dus in de "Mijn documenten\Arduin\libraries" folder gezet worden. Anders kunnen ze wel 100x per dag een nieuwe versie van de IDE uitbrengen.
Zie tevens de link je heb gegeven.

Sketches (dus geen codes; anders ga je de verkeerde terminologie aanleren en begrijpt niemand waar je het over hebt) die niet standaard IDE libraries gebruiken moeten ook gedownload worden en in de eerder aangegeven folder gezet worden. Als alles goed is gaat de rest vanzelf goed.

Verder zou ik je toch echt ten strengste aanbevelen om nog eens door die tutorials te gaan met dien verstande dat kopieren, compileren en downloaden alleen zonde van de tijd is. Probeer te doorgronden wat er gebeurt. Ik weet het dat is vervelend, boring etc etc. Maar als je te veel voor de hand liggende vragen gaat stellen ga je een punt bereiken dat je wat minder antwoorden krijg op jouw vragen. Sommigen hebben inmiddels die ervaring al.

Zoals een belg op een ander forum eens zei "Men geeft jouw geen vis om te eten, maar men leert jouw vissen" of zoiets.....
Docent HBO Technische Informatica, Embedded ontwikkelaar & elektronicus
http://www.verelec.nl

Berichten: 13
Geregistreerd: 11 Jan 2015, 16:25

Re: Problemen met code,s en fouten

Berichtdoor weske2000 » 11 Jan 2015, 20:42

Beste nico

Normaals bedankt ik ga je tips op zeker gebruiken

mvg wesley

Gebruikers-avatar
Berichten: 40
Geregistreerd: 13 Mei 2014, 02:53
Woonplaats: Amsterdam

Re: Problemen met code,s en fouten

Berichtdoor Resu » 12 Jan 2015, 19:19

Ik heb je vraag een week geleden al beantwoord op circuitsonline.net :)
We do what we must because we can.

Terug naar Arduino IDE

Wie is er online?

Gebruikers in dit forum: Geen geregistreerde gebruikers en 11 gasten