I just can't install this library which I need to acces with my ESP32 to a network shared file.
I tried with both of this but doesn't work cant find SMBClient.h
GitHub - aosm/smb
or this
GitHub - sahlberg/libsmb2: SMB2/3 userspace client
nothing works.
Can anyone help me to install this library and compiling will go?
Code is AI created!
What does this mean exactly ?
How did you install the library ?
I tried to download zip file from github and install it, this doesn't work.
Than I unziped folder and copied it into ..\arduino\library folder and this also didn't work.
I have closed arduino ide and reopened it and nothing.
The first library does not seem to be an Arduino library.
The second library states the following for the ESP32 (libsmb2/README at master · sahlberg/libsmb2 · GitHub)
Emphasis added.
This is what I found for library I need.
I need this to compile this script, can anyone help me with this?
Yes it is for ESP32.
#include <WiFi.h>
#include <ETH.h>
#include <SMBClient.h>
// Replace with your network credentials
const char* ssid = "your_SSID";
const char* password = "your_PASSWORD";
// Replace with your network share details
const char* smbServer = "192.168.0.203";
const char* smbShare = "LAN";
const char* smbFile = "on.txt";
const char* smbUser = "your_username"; // If authentication is required
const char* smbPassword = "your_password"; // If authentication is required
// Define the output pin
const int outputPin = 2;
// Ethernet settings
bool eth_connected = false;
void WiFiEvent(WiFiEvent_t event) {
switch (event) {
case SYSTEM_EVENT_ETH_START:
Serial.println("ETH Started");
// Set ETH hostname here
ETH.setHostname("esp32-ethernet");
break;
case SYSTEM_EVENT_ETH_CONNECTED:
Serial.println("ETH Connected");
break;
case SYSTEM_EVENT_ETH_GOT_IP:
Serial.print("ETH IP: ");
Serial.println(ETH.localIP());
eth_connected = true;
break;
case SYSTEM_EVENT_ETH_DISCONNECTED:
Serial.println("ETH Disconnected");
eth_connected = false;
break;
case SYSTEM_EVENT_ETH_STOP:
Serial.println("ETH Stopped");
eth_connected = false;
break;
default:
break;
}
}
void setup() {
// Initialize serial communication
Serial.begin(115200);
// Initialize the output pin
pinMode(outputPin, OUTPUT);
// Initialize Ethernet
WiFi.onEvent(WiFiEvent);
ETH.begin();
// Connect to Wi-Fi
WiFi.begin(ssid, password);
Serial.print("Connecting to WiFi...");
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.print(".");
}
Serial.println("Connected to WiFi");
}
void loop() {
// Check if Ethernet is connected
if (eth_connected) {
Serial.println("Using Ethernet");
if (checkFileExists(smbServer, smbShare, smbFile, smbUser, smbPassword)) {
digitalWrite(outputPin, HIGH); // Set pin HIGH if file exists
} else {
digitalWrite(outputPin, LOW); // Set pin LOW if file does not exist
}
} else {
Serial.println("Using WiFi");
if (checkFileExists(smbServer, smbShare, smbFile, smbUser, smbPassword)) {
digitalWrite(outputPin, HIGH); // Set pin HIGH if file exists
} else {
digitalWrite(outputPin, LOW); // Set pin LOW if file does not exist
}
}
// Wait for 10 seconds before checking again
delay(10000);
}
bool checkFileExists(const char* server, const char* share, const char* file, const char* user, const char* password) {
SMBClient smb;
smb.setCredentials(user, password);
smb.connect(server, share);
bool exists = smb.exists(file);
smb.disconnect();
return exists;
}
As @sterretje has already pointed out, neither of the two libraries you've listed are intended to work with the Arduino environment.
Logically, you should be using whatever library was recommended wherever you "found" the sketch for "the library you need". Expecting others to be able to read your mind and "just know" where you "found" that sketch and therefore know what library it requires is unrealistic.
this sketch is made by AI.
what I need is a sketch which will check if there is on shared folder on network a txt file and if it is I get 1 on pin 19 if it is not than I get 0 on pin 19.
And there is redundancy for LAN connection if it goes off than it connect to Wifi.
Is there any other way to do this?
Ask AI which library it used.
Further I have no idea.
Then no wonder the sketch doesn't work. The AI couldn't find a correct answer so it made one up. That's what generative AIs do. There likely isn't any such library except in the hallucinations of whatever AI you used.
And that's why you can't use a generative AI to do any task that you aren't capable of doing yourself. Because you won't be able to tell when it's lying to you.
Good-bye.
I did and it give me what I posted here at the top.
I was once paid to port SMB to a particular platform so I remember a bit about it. As pointed out, the first lib you found is not for Arduino ecosystem. The second is a possibility as it is for the PICOW but you will need to either be a quick learner or already very experienced especially in porting code to new platforms. If you use AI, please post that in the Topic and first line of your post.
So there is no way to do this.....
That is not what I said. It is doable, but do you have the experience and know how, I have no idea.
Instead of asking how to implement your solution that may or may not be the best solution, instead start with a question to the forum along the lines of 'I need to ........, how can that be done'? And that question does not include pin 19 etc, keep it high level so the hundreds of helpers are free to be creative.
I THINK what you want is to have a way to know that a certain file that is shared (need OS info and sharing methodology in the next step) and on a certain network and is of type txt.
I know it's not Samba but FTP could do what you need.
thank you but don't know how can implement this into script
yes you are right. Problem is because I know verry little of programming arduino
I found a solution here is AI created script which works good. If anyone need it.
It doesn't check if file exist on shared network folder but in web page.
All I need is to connect a LAn module to it, but I need to figure out how to do it properly.
#include <WiFi.h>
#include <ETH.h>
#include <HTTPClient.h>
// Replace with your network credentials
const char* ssid = "WIFI SSID";
const char* password = "PASSWORD";
// Replace with your file URL
const char* fileURL = "http://192.168.0.2/on.txt";
// Define the output pin
const int outputPin = 19;
// Ethernet settings
bool eth_connected = false;
void WiFiEvent(WiFiEvent_t event) {
switch (event) {
case ARDUINO_EVENT_ETH_START:
Serial.println("ETH Started");
// Set ETH hostname here
ETH.setHostname("esp32-ethernet");
break;
case ARDUINO_EVENT_ETH_CONNECTED:
Serial.println("ETH Connected");
break;
case ARDUINO_EVENT_ETH_GOT_IP:
Serial.print("ETH IP: ");
Serial.println(ETH.localIP());
eth_connected = true;
break;
case ARDUINO_EVENT_ETH_DISCONNECTED:
Serial.println("ETH Disconnected");
eth_connected = false;
break;
case ARDUINO_EVENT_ETH_STOP:
Serial.println("ETH Stopped");
eth_connected = false;
break;
default:
break;
}
}
void setup() {
// Initialize serial communication
Serial.begin(115200);
// Initialize the output pin
pinMode(outputPin, OUTPUT);
// Initialize Ethernet
WiFi.onEvent(WiFiEvent);
ETH.begin();
// Connect to Wi-Fi
WiFi.begin(ssid, password);
Serial.print("Connecting to WiFi...");
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.print(".");
}
Serial.println("Connected to WiFi");
}
void loop() {
// Check if Ethernet is connected
if (eth_connected) {
Serial.println("Using Ethernet");
if (checkFileExists(fileURL)) {
digitalWrite(outputPin, HIGH); // Set pin HIGH if file exists
} else {
digitalWrite(outputPin, LOW); // Set pin LOW if file does not exist
}
} else {
Serial.println("Using WiFi");
if (checkFileExists(fileURL)) {
digitalWrite(outputPin, HIGH); // Set pin HIGH if file exists
} else {
digitalWrite(outputPin, LOW); // Set pin LOW if file does not exist
}
}
// Wait for 10 seconds before checking again
delay(10000);
}
bool checkFileExists(const char* url) {
HTTPClient http;
http.begin(url);
int httpCode = http.GET();
http.end();
// Return true if the HTTP response code is 200 (OK)
return (httpCode == HTTP_CODE_OK);
}
Good luck with that. I don't help with AI generated code so I will bow out.
Thank you for all. I don't need help anymore because this code works.
