Giter Club home page Giter Club logo

Comments (8)

dborovcanin avatar dborovcanin commented on June 2, 2024

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.

andychao217 avatar andychao217 commented on June 2, 2024
      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.

andychao217 avatar andychao217 commented on June 2, 2024

am i writing the correct code ?

from magistrala.

dborovcanin avatar dborovcanin commented on June 2, 2024

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.

andychao217 avatar andychao217 commented on June 2, 2024

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.

dborovcanin avatar dborovcanin commented on June 2, 2024

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.

andychao217 avatar andychao217 commented on June 2, 2024

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/ or ws://localhost/ws/channels/.

from magistrala.

dborovcanin avatar dborovcanin commented on June 2, 2024

Can you try using Postman or some other tool that is not running from the browser?

from magistrala.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.