GithubHelp home page GithubHelp logo

Comments (7)

AdrienAdB avatar AdrienAdB commented on June 15, 2024 1

Yes it is a constant, you can assign random ID to each socket.
Please find extract from 1 of my project:

const client = new tbClient({
  host: "your-host",
  publicId: "public-id"
});

const now = Date.now();
const mtd = now-3600000;

const device1 = {
  cmdId: 10,
  entityId: 'your-access-token-1',
  startTs: mtd,
  endTs: now
};

const device2 = {
  cmdId: 11,
  entityId: 'your-access-token-2',
  startTs: mtd,
  endTs: now
};

const MySocket = (props) => {

    const [ connected, setConnected ] = useState(false);

    const openSocket = async () => {

      let token = await client.connect(true);

      if(token){

        setConnected(true);

        client.subscribe(device1, async function(response){


          if(response && response.data){
             console.log('device1', response.data);
          }


        });

      } else {
        setTimeout(() => openSocket(), 5000);
      }

    }

    useEffect(() => {
      if(!connected){ openSocket(); }
    },[connected]);

    return(<div></div>);

}

from thingsboard-js-sdk.

AdrienAdB avatar AdrienAdB commented on June 15, 2024 1

I just created a new issue #5 , publicId belongs to a public dashboard.
You can connect with user/password auth instead or creating a public dashboard.

from thingsboard-js-sdk.

AdrienAdB avatar AdrienAdB commented on June 15, 2024

Hello,
We have a basic example here for React: https://github.com/acte-technology/thingsboard-js-sdk/blob/master/docs/reactjs.js

For WebSocket, you can run this, and check response from callback:
https://github.com/acte-technology/thingsboard-js-sdk#wss-websocket-subscribe

from thingsboard-js-sdk.

thinhvotruong35 avatar thinhvotruong35 commented on June 15, 2024

Thanks for your quick reply, I have use example to connect successful by user and password. I consider about how to check WebSocket id, does it is a const? and how to check response from callback

from thingsboard-js-sdk.

thinhvotruong35 avatar thinhvotruong35 commented on June 15, 2024

After run your code, I got this error, I think because wronged about the "publicId", does it is the device id?
image

from thingsboard-js-sdk.

thinhvotruong35 avatar thinhvotruong35 commented on June 15, 2024

Thank you, It seems app worked but it say "WebSocket Closed", do you have any idea for this
image

from thingsboard-js-sdk.

AdrienAdB avatar AdrienAdB commented on June 15, 2024

Yes, sorry for late reply.
When socket is closed, it's response becomes null.
You can simply run openSocket() if response == null.

from thingsboard-js-sdk.

Related Issues (4)

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.