Comments (8)
Hello @andychao217. Please fill in the issue template properly. However, from the log you shared, it seems you are not using the correct Thing key for the authorization. Please check docs: https://docs.magistrala.abstractmachines.fr/messaging/#websocket. Also, when sharing code snippets, please share them as code block
so we can easily reproduce and copy things for debugging.
from magistrala.
var secret = "{{.Entity.Credentials.Secret}}";
function setupWebSocket() {
let ws = null;
function connect() {
const channelId = "91b2957b-fabd-45f9-8ec0-1509028426bc";
const socketUrl = "ws://192.168.1.151:8186/ws/channels/" + channelId + "/messages?authorization=" + secret
const ws = new WebSocket(socketUrl);
ws.onopen = function(event) {
console.log('WebSocket connected');
};
ws.onclose = function(event) {
console.log('WebSocket disconnected');
setTimeout(connect, 1000);
};
ws.onerror = function(error) {
console.error('WebSocket error observed:', error);
};
ws.onmessage = function(event) {
console.log('Message from server:', event.data);
};
}
connect();
}
setupWebSocket();
from magistrala.
am i writing the correct code ?
from magistrala.
It depends on what's the secret value. From the log, it looks like it's 12345678-2
which is a wrong Thing key format and probably a wrong Thing Key. The code otherwise looks OK.
from magistrala.
magistrala-ws | {"time":"2024-04-15T08:50:11.605301548Z","level":"INFO","msg":"subscribed with client_id to topics /channels/91b2957b-fabd-45f9-8ec0-1509028426bc/messages"}
magistrala-ws | {"time":"2024-04-15T08:50:11.607885874Z","level":"WARN","msg":"WS Proxy failed to upgrade connection","error":"websocket: request origin not allowed by Upgrader.CheckOrigin"}
magistrala-ws | {"time":"2024-04-15T08:50:11.608520579Z","level":"INFO","msg":"Subscribe completed successfully","duration":"56.991872ms","channel_id":"91b2957b-fabd-45f9-8ec0-1509028426bc"}
magistrala-ws | {"time":"2024-04-15T08:50:11.611343794Z","level":"DEBUG","msg":"Successfully upgraded communication to WS on channel 91b2957b-fabd-45f9-8ec0-1509028426bc"}
the system log showed this info
from magistrala.
Also, please check the URL. Looks like you are using both prefix and port, try ws://localhost:8186/channels/
or ws://localhost/ws/channels/
.
from magistrala.
i tried both ways, but still can't establish the connection
Also, please check the URL. Looks like you are using both prefix and port, try
ws://localhost:8186/channels/
orws://localhost/ws/channels/
.
from magistrala.
Can you try using Postman or some other tool that is not running from the browser?
from magistrala.
Related Issues (20)
- Feature: Remove repository error in API response HOT 2
- Feature: Enhance OPC-UA adapter to be more customizable and to perform additional functions HOT 2
- Bug: Unable to enable thing using bootstrap HOT 2
- Feature: Update Magistrala messaging with mProxy with TLS HOT 1
- Generate mocks with mockery for Bootstrap service HOT 2
- Feature: Generate mocks with mockery for Certs service
- Rename Mainflux to Magistrala in HELM charts HOT 1
- Feature: Consume Things connect event in bootstrap HOT 1
- Feature: Generate mocks with mockery for Invitations service
- Feature: Generate mocks with mockery for Lora service
- Feature: Generate mocks with mockery for Consumers service
- Generate mocks with mockery for logger
- Generate mocks with mockery for mqtt
- Generate mocks with mockery for Users service
- Generate mocks with mockery for readers
- Feature: Need to delete things and channels HOT 3
- Feature: Generate mocks with mockery for HTTP service
- Feature: Generate mocks with mockery for Twins service
- Feature: Generate mocks with mockery for Consumer service HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from magistrala.