npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

iot-util

v0.1.6

Published

iot util for Nodejs

Downloads

7

Readme

iot-util

//Use this test.js need node version is higher than 8.9.3 .


const config = {
  loggerConfig: {
    categories: {
      default: {
        appenders: ['console'],
        level: 'info',
      },
    },
    appenders: {
      console: {
        type: 'console',
      },
      redis: {
        type: '@log4js-node/redis',
        host: '127.0.0.1',
        port: 6379,
        pass: '',
        channel: 'iot_log',
        category: 'redis',
        layout: {
          type: 'pattern',
          pattern: '%d{yyyy-MM-dd hh:mm:ss:SSS}#%p#%z#%m',
        },
      },
    },
  },
  mysqlConfig: {
    host: '127.0.0.1',
    user: 'root',
    password: 'root',
    database: 'mysql',
    port: 3306,
  },
  redisConfig: {
    host: '127.0.0.1',
    port: 6379,
    pass: '',
  },
};

const sleep = ms => {
  return new Promise(resolve => {
    setTimeout(resolve, ms)
  })
};
const util = require('../index');
const idGenerator = new util.IdGenerator(1);

function normalFuncTest() {

  console.log('geography.distance ', util.geography.distance(113.82496, 22.73944, 113.82596, 22.73944));
  console.log('geography.convertBaiduToGps ', util.geography.convertBaiduToGps(113.934945,22.531195));

  console.log('PyramidBlock.decodeBlockID ', util.PyramidBlock.decodeBlockID(7009386646791));

  const buf = new Buffer(3);
  buf.writeUInt24BE(65526, 0);
  console.log('Buffer ', buf.readUInt24BE(0));

  console.log('idGenerator ', idGenerator.nextId());

  const logger = new util.Logger(config.loggerConfig, 'iot-util');
  logger.info('username', 'MYSQL', 'getLoggerList', '获取日志分页列表错误: ', '报错了');
}
const mysqlClient = new util.MysqlClient(config.mysqlConfig);
const redisClient = new util.RedisClient(config.redisConfig);
const messageCenter = new util.MessageCenter(config.redisConfig);
const httpClient = new util.HttpClient(config.httpConfig);

async function getPropertymapSqlList(queryParams) {

  const sql = `select help_topic_id,name,help_category_id
    from help_topic
    limit 3`;

  return await mysqlClient.all(sql, queryParams);
}


async function asyncFuncTest() {
  try{
    await sleep(2000);

    console.log('mysql query start');
    const result1 = await getPropertymapSqlList({ user_id: '123213' });
    console.log('mysql.all ', result1);
    // console.log('to query in 30 seconds')
    // await sleep(600000)
    const result2 = await getPropertymapSqlList({ user_id: '123213' });
    console.log('mysql.all ', result2);
    console.log('mysql query finish');


    await redisClient.set('redis_test', 'immmmxxxx');
    await redisClient.setex('redis_test_ex', 10, 'immmmxxxx');
    console.log('redisClient.get.redis_test ', await redisClient.get('redis_test'));
    console.log('redisClient.get.redis_test_ex ', await redisClient.get('redis_test_ex'));
    await sleep(20000);
    console.log('redisClient.get.redis_test ', await redisClient.get('redis_test'));
    console.log('redisClient.get.redis_test_ex ', await redisClient.get('redis_test_ex'));
    
    await redisClient.hset('redis_hash', 'kit', 10);
    await redisClient.hset('redis_hash', 'kit1', '3456f');
    console.log('redisClient.redis_hget ', await redisClient.hget('redis_hash', 'kit'));
    console.log('redisClient.redis_hgetall ', await redisClient.hgetall('redis_hash'));
    console.log('redisClient.redis_hexists ', await redisClient.hexists('redis_hash', 'kit'));
    await redisClient.hdel('redis_hash', 'kit');
    console.log('redisClient.redis_hget ', await redisClient.hget('redis_hash', 'kit'));


    await messageCenter.push('q_test', '如何啊,你收一下');
    console.log('messageCenter.queue ', await messageCenter.pop('q_test'));

    messageCenter.addMessageHandler('mes1', { handle: (topic, message) => console.log('messageCenter.publish.mes1 ', message) });
    messageCenter.addMessageHandler('mes2', { handle: (topic, message) => console.log('messageCenter.publish.mes2 ', message) });
    await messageCenter.publish('mes1', '快来啊');
    await messageCenter.publish('mes2', '来了老弟');
    await messageCenter.publish('mes1', '等你吃饭');

    console.log('http invoke start');
    const url = 'http://apis.map.qq.com/ws/geocoder/v1/?address=%E6%B7%B1%E5%9C%B3%E5%B8%82%E5%AE%9D%E5%AE%89%E5%8C%BA%E8%A5%BF%E4%B9%A1%E5%9C%B0%E9%93%81%E7%AB%99&key=';
    const result = await httpClient.get(url);
    console.log('httpClient.get ', result);

  }catch (err){
    const error = err ? (err.message || err) : undefined;
    console.error(error);
  }
}
normalFuncTest();
asyncFuncTest();