Giter Site home page Giter Site logo

snmp2mqtt's Introduction

SNMP2MQTT

This is a python program to read data from SNMP devices and then publish them to mqtt topics. Configuration can be set by only editing JSON files.

What you need to know:

  1. I assume you:

    • have a basic knowledge about SNMP (if you are a beginner, iReasoning MIB Browser might be an useful tool for you to learn this)
    • use python3.6 or later.

    Python modules needed:

    • easysnmp
    • numpy
    • MySQLdb
    • paho.mqtt
    • pprint
    • psutil

    based on my experience, easysnmp cannot be installed in windows, I recommend you to use Linux OS.

  2. This program also requires MySQL database to be installed. Name, username, and the password of the database can be set in MyDB.py

  3. SNMP devices and their OIDs that want to be read can be configured through JSON files in directory JSON/Config

    a. DevicesIdentity.json contains information about devices identity.

    • Name : Name of the device
    • IPAddress : device ip address
    • SNMPPort : snmp port of the device
    • SNMPVersion : snmp version of the device
    • SNMPReadCommunity : read community
    • SNMPWriteCommunity : write community
    • AccessToken : mqtt username (for authentication with mqtt broker),
    • Timeout : timeout limit for the device

    b. MQTTConfig.json contains settings for mqtt communication and polling interval.

    • PollingInterval : interval of devices data polling
    • BrokerHOST : mqtt broker address
    • MQTTPort : mqtt broker port
    • TopicList : mqtt topic list. for example: ["v1/devices/me/telemetry", "v1/devices/me/attributes"]

    c. DeviceVariables.json contains list of variables in each device with its OID, Datatype, etc.

    • Name : name of the variable
    • OID : Object identifier of the variable
    • Datatype : "INTEGER", "INTEGER32", "UINTEGER", "OCTETSTRING", "OID", "IPADDRESS"
    • isTable : 1 >> if the oid is in table oid, 0 >> if the oid is in regular oid (not in a table)
    • TotalRow : number of row that want to be read in the OID (this is a maxrepetition in GetBulk operation)
    • Multiplier : Value of this variable will be multiplied with this value (if you need numerical data processing)
    • PublishTopic : mqtt topic index in TopicList. The variable value will be published on this topic.
    • Access : R >> for read-only OID, RW >> for read-write OID
  4. To begin data polling, just run the Poller.py. The program will automatically publish the data to mqtt topic periodically, based on the polling interval. The result can also be seen in JSON/Result

  5. Device control (SNMP Set) via MQTT is still in development. But you can do SNMP set operation via Control.py directly.

    Run this command:

    python3.6 Control.py --DeviceNo [Device_Number_Index] --VarName [List_of_variable] --Value [List_of_Value]

    Device_Number_Index ==> device index (based on the order in DevicesIdentity)

    List_of_variable ==> list of variable that want to be set

    List_of_Value ==> list of desired value of each variable

    for example:

    python3.6 Control.py --DeviceNo 1 --VarName acInputOverVoltageValue,acInputUnderVoltageValue --Value 250.4,178.5

    this command will set acInputOverVoltageValue to 250.4 and acInputUnderVoltageValue to 178.5 in the first Device

snmp2mqtt's People

Contributors

vickyysiahaan avatar

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.