Arduino Mega + W5500 + BME280 = Connection refused all the time
-
Well, I am only part way into my first cup of coffee, so maybe my brain just isn't working yet. But so far I am failing to understand what all this
shouldAskandjustAskedbusiness is all about? Why not just do a simple check onmillis()and if enough time has passed, enter the measurement function? Something like:void loop() { if ( millis() > previousBME280Millis + BME280measurementInterval ) { // take measurements, etc... }The way it is presented in OP is, IMO, much more complicated than necessary. Or maybe someone smarter can point out what I am missing?
Your
BME280measurementInterval = 60000(60 seconds), so if you:@NeoX said in Arduino Mega + W5500 + BME280 = Connection refused all the time:
get measurements every 10 seconds
... then it makes me suspect that something is wrong with the main loop there. And if the loop is hogging the CPU, maybe the Ethernet interface can't get a word in edgewise?
But I couldn't seem to figure out the loop, with everything you've got going on there. Maybe I try again in a little while when I have had some coffee and am all the way "on." :D
@TRS-80 I've pasted old version, i;ve modified BME280measurementInterval = 10000
But it doesnt matter, to be honest.
Now ive completely commented out loop() body, and it's still same problem :(Maybe it's some kind of problem with library version?
I found that only compatibile Ethernet library for MySensors is 2.0.0. so i cant downgrade it, but maybe MySensors has some bug here? -
@TRS-80 I've pasted old version, i;ve modified BME280measurementInterval = 10000
But it doesnt matter, to be honest.
Now ive completely commented out loop() body, and it's still same problem :(Maybe it's some kind of problem with library version?
I found that only compatibile Ethernet library for MySensors is 2.0.0. so i cant downgrade it, but maybe MySensors has some bug here?@NeoX said in Arduino Mega + W5500 + BME280 = Connection refused all the time:
Maybe it's some kind of problem with library version?
I found that only compatibile Ethernet library for MySensors is 2.0.0. so i cant downgrade it, but maybe MySensors has some bug here?I just put together Ethernet based gateway (with MQTT, but that shouldn't matter) based on W5500 and Arduino Nano not too long ago. I used platform.io, which (I just double checked my local files) apparently pulled in same v2.0.0 of Ethernet library. And mine works absolutely flawless for a few weeks now.
How about we back up a little and go step by step. Try just the plain (MySensors) Ethernet gateway code and see how that works?
-
@NeoX said in Arduino Mega + W5500 + BME280 = Connection refused all the time:
Maybe it's some kind of problem with library version?
I found that only compatibile Ethernet library for MySensors is 2.0.0. so i cant downgrade it, but maybe MySensors has some bug here?I just put together Ethernet based gateway (with MQTT, but that shouldn't matter) based on W5500 and Arduino Nano not too long ago. I used platform.io, which (I just double checked my local files) apparently pulled in same v2.0.0 of Ethernet library. And mine works absolutely flawless for a few weeks now.
How about we back up a little and go step by step. Try just the plain (MySensors) Ethernet gateway code and see how that works?
-
@NeoX said in Arduino Mega + W5500 + BME280 = Connection refused all the time:
Well what can i say, it works. I can ping, just after a reboot i can connect to 5003 via telnet.
When i close connection (by ctrl+] and close), then i cannot connect to it againWas this with the plain (MySensors) Ethernet code? Or your code from OP with the loop commented out?
-
@NeoX said in Arduino Mega + W5500 + BME280 = Connection refused all the time:
Well what can i say, it works. I can ping, just after a reboot i can connect to 5003 via telnet.
When i close connection (by ctrl+] and close), then i cannot connect to it againWas this with the plain (MySensors) Ethernet code? Or your code from OP with the loop commented out?
-
OK, so it appears the Ethernet part works? I am still not sure what this is about though?:
@NeoX said in Arduino Mega + W5500 + BME280 = Connection refused all the time:
When i close connection (by ctrl+] and close), then i cannot connect to it again
Other than this (potential?) problem, if Ethernet works, brings me back to what I speculated above about the main loop running too much...
-
OK, so it appears the Ethernet part works? I am still not sure what this is about though?:
@NeoX said in Arduino Mega + W5500 + BME280 = Connection refused all the time:
When i close connection (by ctrl+] and close), then i cannot connect to it again
Other than this (potential?) problem, if Ethernet works, brings me back to what I speculated above about the main loop running too much...
-
I just checked my local files for my gateway, and looks like MySensors is v2.3.2.
I am inclined to think the problem is somewhere else, before assuming a bug in MySensors, however it is possible (although unlikely IMO) that potentially could be the problem. One easy way to find out, anyway... ;)
-
@TRS-80 But it's not possible, or some bug in Mysensors.
Because in plain example the loop in sketch is empty.
Do you use lib version 2.3.3 of MySensors lib? -
I just checked my local files for my gateway, and looks like MySensors is v2.3.2.
I am inclined to think the problem is somewhere else, before assuming a bug in MySensors, however it is possible (although unlikely IMO) that potentially could be the problem. One easy way to find out, anyway... ;)
-
Didn't you say plain sketch was working? Other than only being able to connect only once via telnet?
To be honest I am not familiar with using telnet for testing this sort of thing, so I installed it here on my Debian development machine to try and replicate what you are doing, but so far no luck. Probably because first time with tool and simply haven't figured it out yet. But this is what I get so far (probably doing something wrong):
┌─[ 2020-06-26 09:33 trs80@host:~ ] └─▶ $ telnet 192.168.x.y 1883 Trying 192.168.x.y... telnet: Unable to connect to remote host: Connection refused ┌─[ 2020-06-26 09:33 trs80@host:~ ] └─▶ $ telnet 192.168.x.y:1883 telnet: could not resolve 192.168.x.y:1883/telnet: Name or service not knownNote I am running an MQTT gateway, therefore I set port 1883 in my sketch, furthermore I am running in MY_GATEWAY_MQTT_CLIENT mode (I think I read server mode is default in plain (non-MQTT) Ethernet sketch? not sure). So that could be part of my problem here, too.
-
Didn't you say plain sketch was working? Other than only being able to connect only once via telnet?
To be honest I am not familiar with using telnet for testing this sort of thing, so I installed it here on my Debian development machine to try and replicate what you are doing, but so far no luck. Probably because first time with tool and simply haven't figured it out yet. But this is what I get so far (probably doing something wrong):
┌─[ 2020-06-26 09:33 trs80@host:~ ] └─▶ $ telnet 192.168.x.y 1883 Trying 192.168.x.y... telnet: Unable to connect to remote host: Connection refused ┌─[ 2020-06-26 09:33 trs80@host:~ ] └─▶ $ telnet 192.168.x.y:1883 telnet: could not resolve 192.168.x.y:1883/telnet: Name or service not knownNote I am running an MQTT gateway, therefore I set port 1883 in my sketch, furthermore I am running in MY_GATEWAY_MQTT_CLIENT mode (I think I read server mode is default in plain (non-MQTT) Ethernet sketch? not sure). So that could be part of my problem here, too.
@TRS-80 The plain sketch is working in Server mode, so it is possible to connect to port 5003.
Since i don't know any tools to test MySensors ethernet, i've used telnet :)My plain Ethernet example sketch is working, but only for one time after reset, which is weird. Just like some resources hasn't been released or W5500 didnt realised that connection was closed after ctrl+] ?
No idea...
I will take a look at MQTT, since it is working in Client mode... -
@TRS-80 The plain sketch is working in Server mode, so it is possible to connect to port 5003.
Since i don't know any tools to test MySensors ethernet, i've used telnet :)My plain Ethernet example sketch is working, but only for one time after reset, which is weird. Just like some resources hasn't been released or W5500 didnt realised that connection was closed after ctrl+] ?
No idea...
I will take a look at MQTT, since it is working in Client mode... -
Well, i tested MQTT and it worked just fine for a few minutes. Any problems.
I belive that there is some kind of bug in TCP server mode or maybe W5500 driver?
I can also say that when i close telnet connection via ctrl+] i can see that my PC is still waiting for close ack ( connection state in netstat is WAIT_FIN_2).Don't know, but i switched to MQTT and it works fine, and i think MQTT client is more important for me.
-
@NeoX Maybe not relevant, but that doesn't appear to be the Adafruit BME280, as you're including <bme280_mod-1022.h>. This headerfile appears to be part of this library: https://github.com/embeddedadventures/BME280 which is very different from the Adafruit implementation.
If that library blocks too long in one of its calls it might cause troubles. -
@NeoX Maybe not relevant, but that doesn't appear to be the Adafruit BME280, as you're including <bme280_mod-1022.h>. This headerfile appears to be part of this library: https://github.com/embeddedadventures/BME280 which is very different from the Adafruit implementation.
If that library blocks too long in one of its calls it might cause troubles. -
@Yveaux Hmm, interesting, since only one library i do find in Arduino IDE library manager as installed was this Adafruit.
But's should be fine@NeoX said in Arduino Mega + W5500 + BME280 = Connection refused all the time:
only one library i do find in Arduino IDE library manager
I started using PlatformIO recently, and I much prefer their way of searching libraries. When you do
pio runit will even take thelibrary.hfile name that you are missing and give you a link to look it up in their library search. You can also search there for library name, or file names. Very handy!Anyway, a bit offtopic for this thread, so recently I started another one where we can discuss PlatformIO (if you are interested).
@NeoX said in Arduino Mega + W5500 + BME280 = Connection refused all the time:
i switched to MQTT and it works fine, and i think MQTT client is more important for me
I rebuilt my gateway recently (few weeks ago) and this time I decided to go MQTT way. I actually have MQTT broker running on separate machine from my HA controller. Sort of distributed architecture, if you will. So far I am really liking this approach. Soon I will add some additional monitoring and metrics based directly off the MQTT, these will also be totally independent of the controller.