Closed AlessioSavelli closed 1 year ago
Hi, I don't quite understand what you want. if you are using something other than esp32, you can add support for your device. if you want to add a wired connection to esp32, then you don’t really need to modify anything, as far as I understand
This is my Hardware configuration.
Is possible to modify the library to accept my ethrnet socket ?
Ex. Now with your library i need to initialize WiFi and after that i do this : const unsigned short mqttPort=1883; broker.init(mqttPort);
I wolud like to initialize my ethernet and after that do like something this : const unsigned short mqttPort=1883; broker.init(mqttPort,EthTCPServer,EthTCPClient);
Your device like WT32_ETH01?
nope WT32_ETH01 use Chip LAN8720A , i use Chip W5500 or ENC28J60.... I have an idea of the change you should make to the library .... can I suggest it?
oh yes, I understand that there is a different chip, but I'm in terms of software connection. did you watch this topic #19? If the library to connect is the same, then you don't have to add anything. In any case, it is interesting to hear your suggestion for the code.
i try to make a pull request. let's me knwo if you can see it
done
Now you can add your client and server. Let me know if it helped or not.
Yes, in part. i created my file smqtt_user_socket.h and put this code insde:
class TCPClient: EthernetClient { public: bool isConnected() { if (Ethernet.linkStatus() == LinkON) return true; return false; } }; class TCPServer: EthernetServer { public: void stop() {} bool isConnected() { if (Ethernet.linkStatus() == LinkON) return true; return false; } };
but after i initialize the broker i get this error: 192.168.1.177 [ 730][V][WiFiServer.h:42] WiFiServer(): WiFiServer::WiFiServer(port=1883, ...)
assert failed: tcpip_send_msg_wait_sem IDF/components/lwip/lwip/src/api/tcpip.c:455 (Invalid mbox)
Backtrace:0x400834f9:0x3ffb25200x40087ff5:0x3ffb2540 0x4008cd6d:0x3ffb2560 0x400dedba:0x3ffb2690 0x400e93d5:0x3ffb26c0 0x400e9408:0x3ffb26e0 0x400dec31:0x3ffb2730 0x400d2266:0x3ffb2750 0x400d22dc:0x3ffb27a0 0x400d21e9:0x3ffb27c0 0x400d1ad3:0x3ffb27e0 0x400d45ee:0x3ffb2820
ELF file SHA256: 0000000000000000
Rebooting... ets Jul 29 2019 12:21:46
rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT) configsip: 0, SPIWP:0xee clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00 mode:DIO, clock div:2 load:0x3fff0030,len:1344 load:0x40078000,len:13836 load:0x40080400,len:3608 entry 0x400805f0
I don't understand why it says this: : [ 730][V][WiFiServer.h:42] WiFiServer(): WiFiServer::WiFiServer(port=1883, ...)
can you help me?
Show how you init Ethernet
This is my example EthernetBrocker With W5500
byte mac[] = { 0xBE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; byte ip[] = { 192, 168, 1, 177 }; sMQTTBroker broker;
void setup() { Serial.begin(115200); delay(100);
Ethernet.init(ETH_SPI1_CS); Ethernet.begin(mac, ip); // print your local IP address: Serial.println(Ethernet.localIP()); const unsigned short mqttPort = 1883; broker.init(mqttPort); // print your local IP address: Serial.println(Ethernet.localIP()); // all done } void loop() { // broker.update(); }
Insert define before include
the problem remains....
Now to avoid conflicts I have modified the file 'sMQTTplatform.h' like this:
// create and write your client and server //#include "smqtt_user_socket.h"
ecc....
and my .ino like this :
byte mac[] = { 0xBE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; byte ip[] = { 192, 168, 1, 177 }; sMQTTBroker broker; ecc.
Work? Write compiler log with conflict
If i do not remove '#include "smqtt_user_socket.h"' from sMQTTplatform.h the compiler says :
C:\Users\AS\Documents\Arduino\libraries\sMQTTBroker\src/sMQTTplatform.h:8:10: fatal error: smqtt_user_socket.h: No such file or directory
ets Jul 29 2019 12:21:46
rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT) configsip: 0, SPIWP:0xee clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00 mode:DIO, clock div:2 load:0x3fff0030,len:1344 load:0x40078000,len:13836 load:0x40080400,len:3608 entry 0x400805f0 192.168.1.177 [ 728][V][WiFiServer.h:42] WiFiServer(): WiFiServer::WiFiServer(port=1883, ...)
assert failed: tcpip_send_msg_wait_sem IDF/components/lwip/lwip/src/api/tcpip.c:455 (Invalid mbox)
Backtrace:0x40083535:0x3ffb25200x40088089:0x3ffb2540 0x4008d185:0x3ffb2560 0x400e3316:0x3ffb2690 0x400ef81d:0x3ffb26c0 0x400ef87c:0x3ffb26e0 0x400e304d:0x3ffb2730 0x400d56ea:0x3ffb2750 0x400d5760:0x3ffb27a0 0x400d2705:0x3ffb27c0 0x400d1f33:0x3ffb27e0 0x400d7812:0x3ffb2820
ELF file SHA256: 0000000000000000
Rebooting...
change in sMQTTPlatform.h
#if defined(SMQTT_USER_SOCKET)
// create and write your client and server
//#include"smqtt_user_socket.h"
#include<Arduino.h>
#include <Ethernet.h>
#define TCPClient EthernetClient
#define TCPServer EthernetServer
#define SMQTT_LOGD
#elif defined(WIN32)
Also check that this EthernetServer is working without a sMQTTBroker.
I checked the build on my esp in arduino id 2, unfortunately you can’t set SMQTT_USER_SOCKET globally, if you enable the build log in the settings, you can see that it will first compile the libraries and then the sketch. I suggest trying the following: in sMQTTPlatform.h
#define SMQTT_USER_SOCKET
#if defined(SMQTT_USER_SOCKET)
#include <Ethernet.h>
class _EthernetServer :public EthernetServer
{
public:
_EthernetServer(uint16_t port):EthernetServer(port) {}
virtual void begin() { EthernetServer::begin(); }
virtual void begin(uint16_t port) { EthernetServer::begin(); }
void end() {}
};
typedef _EthernetServer TCPServer;
typedef EthernetClient TCPClient;
#define SMQTT_LOGD
I have everything assembled and there were no errors when debugging. I hope this helps you.
nothing is happening, i still have the same problem....
Did you modify in smqttplatform.h ?
yep
I can't fix it in any way....
i will change the library so you can add your server but it will take some time
I'm also surprised that the code I wrote didn't work for you
#include<sMQTTplatform.h>
#include<sMQTTBroker.h>
sMQTTBroker broker;
int main(int argc,char **argv)
{
sMQTTOSServer *server = newsMQTTServer(1883);
broker.init(server);
int time = GetTickCount();
for (;;)
{
broker.update();
if (GetTickCount() - time > 1000)
{
broker.publish(std::string("test"), "test",0);
time = GetTickCount();
}
}
return 0;
}
For your own platform, you need to write your own class for the server and client, as an example, you can look at sMQTTWIN32.h or sMQTTESP32.h
Can you make an example ?
Can you make an example ?
#include"sMQTTBroker.h"
class MyClient: public sMQTTOSClient
{
public:
int available(){return 0;}
unsigned char read(){return 0;}
void write(const char *buffer, unsigned long size){}
void stop(){}
bool connected(){return false;}
};
class MyServer: public sMQTTOSServer
{
public:
void begin(){}
void end(){}
sMQTTOSClient *available(){return new MyClient();}
bool isConnected(){return true;}
};
sMQTTBroker broker;
void setup()
{
MyServer *server=new MyServer();
broker.init(server);
// all done
}
void loop()
{
broker.update();
}
Stale issue message
Hi, you do an amazing work. It is possible to modify the library to can receive my custom TCP Client and TCP Server? I would like to use Ethernet W5500 and ENC28J60 with ESP32.
Thanks you....