Coder Social home page Coder Social logo

microsdi12's Introduction

microSDI12

A mini SDI-12 implementation for getting sensor info over UART using directional RS-485.

API

class SDI12

_init_ (pin_txd, pin_rxd, pin_direction, uart_bus_id)

  • TX pin name
  • RX pin name
  • Direction pin name (optional)
  • UART bus id (optional, default = 1)

is_active (address)

  • args:
    • SDI-12 sensor address. Typical range: 0-9.
  • returns:
    • Boolean: whether the sensor has send back acknowledgment

get_sensor_info (address)

  • args:
    • SDI-12 sensor address. Typical range: 0-9.
  • returns:
    • Tuple (manufacturer, model): The manufacturer and model name as reported by the sensor. If sensor is unreachable, returns (None, None)

get_measurement (address, measurement_name="M")

Sends a request for data measurement to the sensor and returns the data provided by the sensor split into an array. Supports parsing all possible values provided through multiple sequential requests on the sensor. Example:

  > aM!
  < a1329 (address + max 132 seconds of waiting + 9 expected values )
  > aD0!
  < a+1+2-3+4.1+5 (5 values read so there will be an additional request for extra data)
  > aD1!
  < a+6+7+8+9

  output: [1, 2, -3, 4.1, 5, 6, 7, 8, 9]
  • args:
    • SDI-12 sensor address. Typical range: 0-9.
    • measurement_name: Configures the name of the query. Default is "M" as the default query is "aM!".
  • returns:
    • Measurement data array: an array containing all the data collected from the sensor. For details on each data value, please advise sensor manufacturer manuals. If sensor is unreachable, returns None

Example

from microsdi12 import SDI12

sdi12 = None

try:
    sdi12 = SDI12("P3", "P4", "P8", 1)

    manufacturer = None
    model = None
    sensor_response = None
    address = "1"

    if sdi12.is_active(address):
        manufacturer, model = sdi12.get_sensor_info(address)
        response_array = sdi12.get_measurement(address)
        print(response_array)
except Exception as e:
    print("Exception while reading SDI-12 data")
finally:
    if sdi12:
        sdi12.close()

links

microsdi12's People

Contributors

ftylitak avatar

Watchers

 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.