Git Product home page Git Product logo

smartpump-firmware's Introduction

smartpump-firmware

Firmware for an off-grid water pumping system

Hardware overview

Development setup

Install Visual Studio Code and the PlatformIO extension.

Copy include/NetworkConfiguration.h.example to include/NetworkConfiguration.h and insert your The Things Network configuration.

Edit the platformio.ini file and change the board_build.arduino.lorawan.region to the correct frequency band for your country.

Attach a serial monitor and read the Device EUI after a reset. Then set the device EUI in the TTN console, use OTAA and MAC 1.0.2 .

Use the PlatformIO menu to compile and upload the code.

TTN configuration

Uplink Payload Formatter

function decodeInt16(bytes, offset)
{
  return (((bytes[offset + 1] & 0xFF) << 8) | (bytes[offset] & 0xFF));
}

function decodeFloat32(bytes, offset)
{
  var d = new DataView(new ArrayBuffer(4));
  for(var i=0; i<4; i++) d.setUint8(i, bytes[offset + i]);
  return d.getFloat32(0, true);
}

function decodeUplink(input) 
{
  return {
    data: {
      bytes: input.bytes,
      id: input.bytes[0],
      current: [
        decodeFloat32(input.bytes, 1),
        decodeFloat32(input.bytes, 5),
        decodeFloat32(input.bytes, 9),
        decodeFloat32(input.bytes, 13)
      ],
      adc: [
        decodeFloat32(input.bytes, 17),
        decodeFloat32(input.bytes, 21),
        decodeFloat32(input.bytes, 25),
        decodeFloat32(input.bytes, 29)
      ]
    },
    warnings: [],
    errors: []
  };
}

Downlink Payload Formatter

function encodeDownlink(input) {
  var rel = 0;
  if(input.data.relay[0] === true) rel |= 1;
  if(input.data.relay[1] === true) rel |= 2;
  if(input.data.relay[2] === true) rel |= 4;
  if(input.data.relay[3] === true) rel |= 8;
  return {
    bytes: [ rel ],
    fPort: 1,
    warnings: [],
    errors: []
  };
}

function decodeDownlink(input) {
  return {
    data: {
      bytes: input.bytes,
      relay: [
        input.bytes[0] & 1, 
        input.bytes[0] & 2,
        input.bytes[0] & 4,
        input.bytes[0] & 8
      ]
    },
    warnings: [],
    errors: []
  };
}

Example uplink payload

{
  "id": 1,
  "current": [1.0, 1.0, 1.0, 1.0],
  "adc": [1.0, 1.0, 1.0, 1.0]
}

Example downlink payload

{
  "relay": [true, true, true, true]
}

smartpump-firmware's People

Contributors

stargate01 avatar

Watchers

 avatar  avatar  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.