znalazłem w necie taki program na Arduino ale podczas kompilacji wywala błąd zmiennej char
macie jakiś pomysł w czym jest błąd
Arduino:1.8.16 (Windows Store 1.8.51.0) (Windows 10), Płytka:"Arduino Uno"
C:\Users\User\Desktop\Andruino Pliki\WebServer_moje\WebServer_moje.ino:25:30: warning: invalid conversion from 'char' to 'char*' [-fpermissive]
char *plik = "index.htm"[1000];
~~~~~~~~~~~~~~~~^
C:\Users\User\Desktop\Andruino Pliki\WebServer_moje\WebServer_moje.ino: In function 'void loop()':
WebServer_moje:94:61: error: 'webFile' was not declared in this scope
webFile = SD.open(plik);
^~~~~~~
C:\Users\User\Desktop\Andruino Pliki\WebServer_moje\WebServer_moje.ino:94:61: note: suggested alternative: 'WebFile'
webFile = SD.open(plik);
^~~~~~~
WebFile
exit status 1
'webFile' was not declared in this scope
Ten raport powinien zawierać więcej informacji jeśli w
File -> Preferencje zostanie włączona opcja "Pokaż
szczegółowe informacje podczas kompilacji"
#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>
File WebFile;
char *plik = "index.htm";
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 20, 200);
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);
void setup() {
// You can use Ethernet.init(pin) to configure the CS pin
//Ethernet.init(10); // Most Arduino shields
//Ethernet.init(5); // MKR ETH shield
//Ethernet.init(0); // Teensy 2.0
//Ethernet.init(20); // Teensy++ 2.0
//Ethernet.init(15); // ESP8266 with Adafruit Featherwing Ethernet
//Ethernet.init(33); // ESP32 with Adafruit Featherwing Ethernet
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.println("Inicjalizacja karty pamięci");
if (!SD.begin(4)){
Serial.println("Inicjalizacja nieudana");
return;
}
Serial.println("Inicjalizacja poprawna");
if (!SD.exists(plik)) {
Serial.println("Nie zmaleziono danych na karcie <pliku HTML> (HTML)
" + String(plik));
return;
}
Serial.println("odczyt poprawny" + String(plik) + "serwer za chwile bedzie gotowy" );
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
Serial.print("Server pracuje na adresie IP:");
Serial.println(Ethernet.localIP());
}
void loop() {
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
Serial.println("new client");
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close");
// client.println("Refresh: 5"); // refresh the page automatically every 5 sec
client.println();
webFile = SD.open(plik);
if (webFile) {
while(webFile.available()){
client.write(webFile.read());
}
webFile.close();
}
// client.println("</html>");
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
} else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
Serial.println("client disconnected");
}
}
macie jakiś pomysł w czym jest błąd
Arduino:1.8.16 (Windows Store 1.8.51.0) (Windows 10), Płytka:"Arduino Uno"
C:\Users\User\Desktop\Andruino Pliki\WebServer_moje\WebServer_moje.ino:25:30: warning: invalid conversion from 'char' to 'char*' [-fpermissive]
char *plik = "index.htm"[1000];
~~~~~~~~~~~~~~~~^
C:\Users\User\Desktop\Andruino Pliki\WebServer_moje\WebServer_moje.ino: In function 'void loop()':
WebServer_moje:94:61: error: 'webFile' was not declared in this scope
webFile = SD.open(plik);
^~~~~~~
C:\Users\User\Desktop\Andruino Pliki\WebServer_moje\WebServer_moje.ino:94:61: note: suggested alternative: 'WebFile'
webFile = SD.open(plik);
^~~~~~~
WebFile
exit status 1
'webFile' was not declared in this scope
Ten raport powinien zawierać więcej informacji jeśli w
File -> Preferencje zostanie włączona opcja "Pokaż
szczegółowe informacje podczas kompilacji"
#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>
File WebFile;
char *plik = "index.htm";
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 20, 200);
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);
void setup() {
// You can use Ethernet.init(pin) to configure the CS pin
//Ethernet.init(10); // Most Arduino shields
//Ethernet.init(5); // MKR ETH shield
//Ethernet.init(0); // Teensy 2.0
//Ethernet.init(20); // Teensy++ 2.0
//Ethernet.init(15); // ESP8266 with Adafruit Featherwing Ethernet
//Ethernet.init(33); // ESP32 with Adafruit Featherwing Ethernet
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.println("Inicjalizacja karty pamięci");
if (!SD.begin(4)){
Serial.println("Inicjalizacja nieudana");
return;
}
Serial.println("Inicjalizacja poprawna");
if (!SD.exists(plik)) {
Serial.println("Nie zmaleziono danych na karcie <pliku HTML> (HTML)
return;
}
Serial.println("odczyt poprawny" + String(plik) + "serwer za chwile bedzie gotowy" );
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
Serial.print("Server pracuje na adresie IP:");
Serial.println(Ethernet.localIP());
}
void loop() {
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
Serial.println("new client");
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close");
// client.println("Refresh: 5"); // refresh the page automatically every 5 sec
client.println();
webFile = SD.open(plik);
if (webFile) {
while(webFile.available()){
client.write(webFile.read());
}
webFile.close();
}
// client.println("</html>");
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
} else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
Serial.println("client disconnected");
}
}