Go Down

Topic: error: 'String' does not name a type In function (Read 4285 times) previous topic - next topic

OpenElectronics

Hi,
Compiling a sketch I obtain this error
Code: [Select]

error: 'String' does not name a type In function 'void leggiSeriale()':
At global scope:
In function 'void acquisisciip()':
Bad error line: -20


Can you help me?

I must post the code?
I created two .pde file and I import them in two tab... I don't know if this is correct.



http://www.open-electronics.org

PaulS

Quote
Can you help me?

Yes, we can.

Quote
I must post the code?

Well, you said you wanted help.

deSilva

You most likely forgot to
#include <String.h>

OpenElectronics

Thank you.
I tried to add
#include <String.h>
but doesn't work.
I upload the code here:

http://www.tmpfolder.com/download.php?dir=../upload/6c92469c2448/&filename=ws2300_3.rar

The code is not complete. There are two sketch:
ws2300_3.pde  is the sketch to read the wether station WS2300 / WS2350 / WS2305 WS2308 and it works.
With the serial interface you can ask the WS data.

The other sketch ethernet.pde must be modified. I want to publish WS data on line. When the code is finished, I will publish the work.

Thank you.

IIf someone wants to cooperate, I will be very happy

http://www.open-electronics.org

Coding Badly


OpenElectronics

In the file ethernet.pde I write


#include <Ethernet.h>
#include <WString.h>
#include <EEPROM.h>
#include <NewSoftSerial.h>
#include <String.h>

I must include this header in ws2300.pde also?

probably just a configuration problem ... but I am a beginner and do not find a tutorial on how to solve these problems ... Sorry for the lack

http://www.open-electronics.org

deSilva

The new String (version 0.9 I think) IS the old WString (or TextString).... You might have issues in using both of them. There is no need for this.

OpenElectronics

With or without
#include <String.h>
the compiling doesn't work...
How do I configure the IDE to work with multiple files?

http://www.open-electronics.org

PaulS

You might try this:
Code: [Select]
#include <WString.h>                // include the String library

OpenElectronics

These are my include

#include <Ethernet.h>
#include <WString.h>
#include <EEPROM.h>
#include <NewSoftSerial.h>

http://www.open-electronics.org

PaulS

In the Sketch + Import Library menu, is the String library importable?

OpenElectronics

Ok I solved.
I import the .h in ws2300.pde and not in ethernet.pde...
I did not understand why but it works well now.
Thanks to all.

http://www.open-electronics.org

ull

Do you care to share your current version of this sketch?

OpenElectronics

Yes of course. You can help me...


[code]



//  Copyright (C) 2010 Landoni Boris
//  http://technolando.blogspot.com/
//  http://www.futurashop.it
//  http://www.elettronicain.it/
//
//  WS2300 is free software: you can redistribute it and/or
//  modify it under the terms of the GNU Lesser General Public License
//  as published by the Free Software Foundation, either version 3 of
//  the License, or (at your option) any later version.
//
//  WS2300 is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU Lesser General Public License for more details.

NewSoftSerial mySerial(2, 3);   //NewSoftSerial mySerial(rx,tx);


const int ledPin = 6; // the pin that the LED is attached to
const int rts = 4;
const int dtr = 5;


void leggiSeriale() {
 
 int incomingByteSer;      // a variable to read incoming serial data into
 // see if there's incoming serial data:
 if (Serial.available() > 0) {
   // read the oldest byte in the serial buffer:
   incomingByteSer = Serial.read();
   // if it's a capital H (ASCII 72), turn on the LED:
   Serial.flush();
  if (incomingByteSer == 'R') {
     Serial.println("RESET");
     delay(2000);
     digitalWrite(rts, HIGH);
     digitalWrite(dtr, LOW);
     delay(2000);
     digitalWrite(rts, LOW);
     digitalWrite(dtr, HIGH);
     delay(1000);
     mySerial.print(byte(06));
     delay(1000);
   }  
   if (incomingByteSer == 'o') {
     String data=getTime();
     Serial.print("ora ");
     Serial.println(data);
   }  
   if (incomingByteSer == 'd') {
     String data=getDay();
     Serial.print("giorno ");
     Serial.println(data);
   }  
   if (incomingByteSer == 't') {
     String data=getTempIn();
     Serial.print("temperatura interna ");
     Serial.println(data);
   }
   
   if (incomingByteSer == 'T') {
     String data=getTempOut();
     Serial.print("temperatura esterna ");
     Serial.println(data);
   }
   if (incomingByteSer == 'h') {
     String data=getHumIn();
     Serial.print("umidità interna ");
     Serial.println(data);
   }
   
   if (incomingByteSer == 'H') {
     String data=getHumOut();
     Serial.print("umidità esterna ");
     Serial.println(data);
   }
   
   if (incomingByteSer == 'p') {
     String data=getPress();
     Serial.print("pressione ");
     Serial.println(data);
   }
   
   if (incomingByteSer == 'w') {
     String data=getWind(0);
     Serial.print("wind speed ");
     Serial.println(data);
   }
   if (incomingByteSer == 'W') {
     String data=getWind(1);
     Serial.print("wind dir ");
     Serial.println(data);
   }
   
   if (incomingByteSer == 'r') {
     String data=getRain1();
     Serial.print("rain 1 ");
     Serial.println(data);
   }
   // if it's an L (ASCII 76) turn off the LED:
   if (incomingByteSer == 'L') {
     digitalWrite(ledPin, LOW);
   }
 }
}

// Function to clear a string
void clearStr (char* str) {
  int len = strlen(str);
  for (int c = 0; c < len; c++) {
     str[c] = 0;
  }
}

String Leggi (int mem[]) {
   String inString = String(35);
   int incomingByte;      // a variable to read incoming serial data into
   int time=0;
 /*  Serial.print("memoria ");
   for (int tmp=0; tmp<5; tmp++){
     Serial.print(mem[tmp],HEX);
     Serial.print(" ");
   }
   Serial.println();
   */
   incomingByte=0;
    while ((incomingByte!=2) && (time<20)){
         time++;
         mySerial.print(byte(06));
         delay(20);
         /*while ((mySerial.available() == 0) && (time<100)){
            delay(20);
            time++;      
         }
         time=0;
         */
           if (mySerial.available() > 0) {
             incomingByte = mySerial.read();
             inString.append(incomingByte);
    //         Serial.print("RICEVUTO ");
    //         Serial.println(incomingByte);
           }
     }
   
    clearStr(inString);
    mySerial.flush();
    if (time==100){
    //     Serial.print("errore reset ");  
         return("0");
    }  
     

     
     for (int tmp=0; tmp<5; tmp++){
       mySerial.print(byte(mem[tmp]));
       //Serial.print("-> ");
       //Serial.println((mem[tmp]),HEX);
       while ((mySerial.available() == 0) && (time<100)){
        delay(30);
        time++;      
       }
       if (time==100){
      //   Serial.print("errore ");  
      //   Serial.println(tmp);
         return("0");
         break;  
         
       }        
       time=0;      
       /*if (mySerial.available() > 0) {
         incomingByte = mySerial.read();
         inString.append(incomingByte);
         Serial.print("RICEVUTO ");
         Serial.println(incomingByte,HEX);
       }
     
       */
      //delay(200);
          while (mySerial.available() > 0) {
               delay(20);            
               incomingByte = mySerial.read();
               //inString.append(incomingByte,HEX);
         //      Serial.print("<- ");
         //      Serial.println(incomingByte,HEX);
         //      Serial.println(incomingByte);
               //(incomingByte & B11110000);
               if (tmp<4){
                 //Serial.print("nibble ");
                 //Serial.println(((incomingByte & B11110000)/B10000),HEX);    //isolo il nibble più significativo e lo faccio slittare
                 //Serial.print("tmp ");
                 //Serial.print(tmp);
                 if (tmp!=((incomingByte & B11110000)/B10000)){
          //           Serial.print("confronto ERRATO ");
                     return("0");
                     break;  
                 }
                 //else
                 //{                      
                 //    Serial.print("confronto OK ");  
                 //}  
               }
               if (tmp==4){
                 if (incomingByte<=0xF){
                   inString.append(0);
                 }
                 inString.append(incomingByte,HEX);  
               }
          }
      }
       

 //      Serial.print("stringa ricevuta ");
 //      Serial.println(inString);
       return(inString);
}

String getTime(){
     String dataStr=0;
     Serial.print("leggo ora ");
     int my_array[] = {0x82,0x8A,0x82,0x82,0xDA};
     dataStr= elabTime(my_array);                  
     return(dataStr);
}

String getDay(){
     String dataStr=0;
     Serial.print("leggo giorno ");
     int my_array[] = {0x82,0x8A,0x8E,0xAE,0xEE};
     dataStr= elabDay(my_array);                  
     return(dataStr);
}

String getTempIn(){
     String dataStr=0;
     Serial.print("leggo temperatura interna ");
     int my_array[] = {0x82,0x8E,0x92,0x9A,0xFA};
     dataStr= elabTemp(my_array);                  
     return(dataStr);
}

String getTempOut(){
     String dataStr=0;  
     Serial.print("leggo temperatura esterna ");
     int my_array[] = {0x82,0x8E,0x9E,0x8E,0xFA};
     dataStr= elabTemp(my_array);                  
     return(dataStr);
}

String getHumIn(){
     String dataStr=0;
     Serial.print("leggo umidità interna ");
     int my_array[] = {0x82,0x8E,0xBE,0xAE,0xDA};
     dataStr= elabHum(my_array);                  
     return(dataStr);
}

String getHumOut(){
     String dataStr=0;      
     Serial.print("leggo umidità esterna ");
     int my_array[] = {0x82,0x92,0x86,0xA6,0xDA};
     dataStr= elabHum(my_array);                  
     return(dataStr);
}

String getPress(){
     String dataStr=0;      
     Serial.print("leggo pressione ");
     int my_array[] = {0x82,0x96,0xBA,0x8A,0xD6};
     dataStr= elabPress(my_array);                  
     return(dataStr);
}

String getWind(int dato){
     String dataStr=0;      
     Serial.print("leggo wind ");
     int my_array[] = {0x82,0x96,0x8A,0x9E,0xF2};
     dataStr= elabWind(my_array,dato);                  
     return(dataStr);
}

String getRain1(){
     String dataStr=0;      
     Serial.print("leggo pioggia 1h ");
     int my_array[] = {0x82,0x92,0xAE,0x92,0xDA};
     dataStr= elabRain1(my_array);                  
     return(dataStr);
}

String elabTime(int my_array[]){
           String inString = String(35);
           String dataStr = String(5);
           //float dataFloat=0;
           
       for (int ritenta=0; ritenta<3; ritenta++){
       //    Serial.print("ritenta ");
       //    Serial.println(ritenta);
           
           inString=Leggi(my_array);
           //Serial.print("stringa ricevuta2 ");
           //Serial.println(inString);
           if (inString.length()>5){
               //data= inString.substring(4,6);  //estraggo i decimali della temperatura
               dataStr.append(inString.substring(6,8));  //estraggo i decimali della temperatura
               dataStr.append(":");
               dataStr.append(inString.substring(4,6));  //estraggo i decimali della temperatura
               dataStr.append(":");
               dataStr.append(inString.substring(2,4));  //estraggo le decine e unità della temperatura
               //Serial.print("tempin ricevuta   ");
               //Serial.println(dataStr);
               //tempin=data;
     
               //dataFloat = (atof(dataStr));
               //Serial.print("tempin float   ");
               //Serial.println(dataFloat);
               break

http://www.open-electronics.org

Go Up