-
Notifications
You must be signed in to change notification settings - Fork 11
Add example to the repo #5
Comments
Thanks for your interest. Current master will not work, use commit 81fd79b instead. Explanations: This driver is about to be integrated in the esp8266 arduino core. I am also currently working on a driver compatible with W5100 (#4)
|
Thanks for the fast response I tried several versions of ESP the error i get is the same. It seems to me a issue with a include or something.
|
As I told,
Or, try with the PR esp8266/Arduino#6039 (Well it maybe is not nice of me to to push beta code on master) |
Thank you d-a-v, still watching. Will try soon. |
Current state of this driver will now work with latest git version esp8266 arduino core. |
Tried this example:
with latest Arduino core. Still get this error:
|
Sorry you need to use git version.
The api for Ethernet is still not stable and under heavy discussion.
It should work anyway and I'll update when needed until I can integrate
everything into the arduino core.
|
Thank you for your quick reply! I actually use the version of W5500lwIP from this git repository. We just wait until things have stabilized and continue to watch this repo. |
For some reason at least with latest Arduino core (commit 9f03bbb8c38adf2f6dc9fb95e304b51f20a72f92 #include <SPI.h>
#include <ESP8266WiFi.h>
#include <W5500lwIP.h>
#include <Schedule.h>
Wiznet5500lwIP eth(SPI, D4);
byte mac[] = {0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02};
void setup ()
{
Serial.begin(115200);
WiFi.mode(WIFI_OFF);
SPI.begin();
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SPI_MODE0);
SPI.setFrequency(40000000); // Works up to 80M
eth.setDefault(); // use ethernet for default route
int present = eth.begin(mac);
Serial.println("present= " + String(present, HEX));
while (!eth.connected()) {
Serial.print(".");
delay(1000);
run_scheduled_functions();
}
Serial.println(eth.localIP());
}
void loop ()
{
yield();
} |
@borisneubert
|
Moin d-a-v, I tried to run your latest example. Compiling the demo sketch results the following errors:
Witch core-version do you use? |
Latest git is required ! |
Hi Pfannex, |
core 2.5.2 will not work. |
Ethernet PR on arduino core launched: esp8266/Arduino#6680 |
Moin David, with latest core commit dd73a18 WiFi and also ETH seems to run perfect including:
The Webserver is supported on WiFi-IP and also on ETH-IP. In the next step we will test the lwIP function in our OmniESP-framework... good job! latest test sketch #include <Arduino.h>
//....................................................
// WiFi
#include "ESP8266WiFi.h"
const char *ssid = "xxxxx";
const char *password = "xxxxx";
//....................................................
#define CSPIN 4 // GPIO4
#include <W5500lwIP.h>
Wiznet5500lwIP eth(SPI, CSPIN);
//#include <W5100lwIP.h>
//Wiznet5100lwIP eth(SPI, CSPIN);
int present = 0;
#include <osapi.h>
LOCAL os_timer_t eth_timer;
int led = 0;
//....................................................
// asynchronous web server
#include <ESPAsyncTCP.h>
#include <ESPAsyncWebServer.h>
AsyncWebServer server(80);
//....................................................
// ntp client
#include <NTPClient.h>
#include <WiFiUdp.h>
#define NTPSERVER "91.202.42.83"
//#define NTPSERVER "0.ubuntu.pool.ntp.org"
//#define NTPSERVER "192.53.103.108"
WiFiUDP ntpUDP;
NTPClient ntpClient(ntpUDP, NTPSERVER, 3600, 20000);
unsigned long long t = 0, t0 = 0;
//....................................................
// mqtt client
#include <PubSubClient.h>
WiFiClient espClient;
PubSubClient client(espClient);
const char* mqtt_server = "192.168.1.10";
long lastMsg = 0;
char msg[50];
int value = 0;
String mqttMsg;
// mqtt callback
void callback(char* topic, byte* payload, unsigned int length) {
Serial.println("MQTT incomming subcribe: ");
mqttMsg = topic;
mqttMsg += " - ";
for (int i = 0; i < length; i++) {
mqttMsg += (char)payload[i];
}
Serial.println(mqttMsg);
}
// mqtt reconnect
void reconnect() {
Serial.print("Attempting MQTT connection...");
String clientId = "ESP8266Client-";
if (client.connect(clientId.c_str())) {
Serial.println("connected");
client.publish("outTopic/start", "Hello from W5500!");
client.subscribe("inTopic/#");
} else {
Serial.print("failed, rc=");
Serial.print(client.state());
Serial.println(" try again in 5 seconds");
}
/*
-4 : MQTT_CONNECTION_TIMEOUT - the server didn't respond within the keepalive time
-3 : MQTT_CONNECTION_LOST - the network connection was broken
-2 : MQTT_CONNECT_FAILED - the network connection failed
-1 : MQTT_DISCONNECTED - the client is disconnected cleanly
0 : MQTT_CONNECTED - the client is connected
1 : MQTT_CONNECT_BAD_PROTOCOL - the server doesn't support the requested version of MQTT
2 : MQTT_CONNECT_BAD_CLIENT_ID - the server rejected the client identifier
3 : MQTT_CONNECT_UNAVAILABLE - the server was unable to accept the connection
4 : MQTT_CONNECT_BAD_CREDENTIALS - the username/password were rejected
5 : MQTT_CONNECT_UNAUTHORIZED - the client was not authorized to connect
*/
}
//....................................................
void ICACHE_RAM_ATTR eth_loop(void) {
digitalWrite(LED_BUILTIN, led);
led = 1 - led;
//if(present) eth.loop();
}
bool schedule_function_us(const std::function<bool(void)>& fn, uint32_t repeat_ms = 0);
//####################################################
// setup
//####################################################
void setup() {
// starting example
Serial.begin(115200);
Serial.println("");
delay(1000);
Serial.println("starting example...");
// starting wifi
Serial.println("starting wifi...");
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
int i = 0;
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
i++;
if (i > 20) break;
}
Serial.println("");
if (i > 20) {
Serial.println("wifi connection failed");
} else {
Serial.print("wifi ip address: ");
Serial.println(WiFi.localIP());
Serial.print("wifi hostname: ");
Serial.println(WiFi.hostname());
}
// starting ethernet
// enable Ethernet here-------------------
pinMode(LED_BUILTIN, OUTPUT);
Serial.println("starting ethernet...");
//os_timer_disarm(ð_timer);
//os_timer_setfn(ð_timer, (os_timer_func_t *)eth_loop, NULL);
//os_timer_arm(ð_timer, 1, 1);
SPI.begin();
SPI.setClockDivider(SPI_CLOCK_DIV4); // 4 MHz?
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SPI_MODE0);
eth.setDefault(); // use ethernet for default route
present = eth.begin();
if (!present) {
Serial.println("no ethernet hardware present");
//return;
} else {
Serial.print("connecting ethernet");
while (!eth.connected()) {
Serial.print(".");
delay(1000);
}
Serial.println();
Serial.print("ethernet ip address: ");
Serial.println(eth.localIP());
}
// starting web server
server.on("/", HTTP_GET, [](AsyncWebServerRequest * request) {
String htmlStr = "";
htmlStr += "<HTML>";
htmlStr += "<HEAD>";
htmlStr += "<meta http-equiv=\"refresh\" content=\"1\">";
htmlStr += "<TITLE />WiFi/ETH</title>";
htmlStr += "</head>";
htmlStr += "<BODY>";
htmlStr += "WiFi/ETH";
htmlStr += "<br />";
htmlStr += "WiFi IP: ";
htmlStr += WiFi.localIP().toString();
htmlStr += "<br />";
htmlStr += "ETH IP: ";
htmlStr += eth.localIP().toString();
htmlStr += "<br />";
htmlStr += "Time: ";
htmlStr += ntpClient.getFormattedTime();
htmlStr += "<br />";
htmlStr += "MQTT: ";
htmlStr += mqttMsg;
htmlStr += "<br />";
htmlStr += "</BODY>";
htmlStr += "</HTML>";
request->send(200, "text/html", htmlStr);
});
server.begin();
// starting ntp client
Serial.println("starting ntp client...");
ntpClient.begin();
// starting mqtt client
client.setServer(mqtt_server, 1883);
client.setCallback(callback);
client.subscribe("inTopic");
// ready
Serial.println("setup complete");
}
//####################################################
// loop
//####################################################
void loop() {
while (true)
{
client.loop();
ntpClient.update();
t = ntpClient.getEpochTime();
if (t != t0) {
if (!client.connected()) reconnect();
Serial.println(ntpClient.getFormattedTime());
Serial.print("wifi ip address: ");
Serial.println(WiFi.localIP());
Serial.print("ethernet ip address: ");
Serial.println(eth.localIP());
//Serial.println(eth.begin());
client.publish("outTopic", ntpClient.getFormattedTime().c_str());
t0 = t;
uint32_t mfree;
uint16_t mmax;
uint8_t frag;
ESP.getHeapStats(&mfree, &mmax, &frag);
Serial.printf("%d %d %d\n", mfree, mmax, frag);
}
yield();
}
} |
Thanks for testing, for the report ! |
Hi David, right now we implement your lwIP into our framework. Every time the state of the ETH-connection changes we also want to change the default route. Therefor you implemented: template <class RawEthernet>
void LwipEthernet<RawEthernet>::setDefault ()
{
Serial.println("set ETH to default, revise if not connected!");
_default = true;
if (connected())
netif_set_default(&_netif);
}
#endif // _LWIPETH_H How to make it switchable? like void LwipEthernet<RawEthernet>::setDefault (boolean state)
{
_default = state;
netif_set_default(&_netif);
} or like void LwipEthernet<RawEthernet>::setDefault ()
{
if (connected()){
_default = true;
}else{
_default = false;
}
netif_set_default(&_netif);
} |
I think it would work: (why)
|
It would be nice to add the example given here #3 (comment) as a example to the repository.
It could save some people some searching for the correct pin connection.
Thanks for making this. Ill test it later today.
The text was updated successfully, but these errors were encountered: