Closed gustschaefer closed 4 years ago
Is it possible you are thinking about MQTT and not websockets?
I don't think so, it's an adonis websockets. I can connect to the server but not on the topic. I was able to connect using javascript with the function "ws.subscribe()" .
the server url is: wss://**.com/adonis-ws
I don't think so. And you can't just subscribe universally to a websocket channel. It depends on the framework of the WS server. Here is an example I was using to subscribe to a Phoenix websocket channel:
const char* joinTemplate = "{\"topic\":\"controller:%s\",\"event\":\"phx_join\",\"payload\":{\"name\":\"%s\"},\"ref\":0}";
void sendPhoenixJoin(WebsocketsClient *client, const char* deviceId, const char* deviceName)
{
char result[500];
sprintf(result, joinTemplate, deviceId, deviceName);
client -> send(result);
}
I joined and subscribed to the channel/topic of controller:1
with this code. As you can see the event is phx_join
and will most likely be different on, let's say, NodeJS.
Note:
I probably could have used &
instead of pointers in the function declaration but I really didn't try.
Edit:
Yep, I could optimize this to not use a char array of 500, but I honestly at the time of writing code just for proof of concept, optimization wasn't a deal-breaker.
Edit v2:
@gilmaimon I guess you can close this issue as it is server-framework-specific.
@gustschaefer I would prefer that the way you resolve this issue for yourself is to code a small websocket server in non-JS and then see the direct JSON payload which the JS client sends to your websocket server.
When you know the direct string version of the payload, implement that in your Arduino and it should work. That's what I've done when I've implemented this library for my Phoenix webserver.
Good job helping out @zastrixarundell !
Anyway @gustschaefer your question is as I said, not related to the library itself but more of a generic programming question, and you got a great answer.
Closed.
I was able to connect to the server, but when I tried to subscribe in a topic called "test" it doesn't work, I dont know if I need call a libary function or what. Can anyone help with this or recommend me other libary for WebSockets in order to do this?