Giter Site home page Giter Site logo

lucasdietrich / caniot-device Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 1.67 MB

Generic firmware for ATmega328p for temperature monitoring, control of IOs and other external devices from a gateway using CAN protocol.

License: Apache License 2.0

C++ 16.32% C 81.16% Python 1.95% Makefile 0.05% Dockerfile 0.52%
can arduino atmega328p pcf8574 tcn75 iot

caniot-device's Introduction

CAN-IoT device (v2)

Disclaimer: This is a still work in progress personal project. I'm having fun reinventing the wheel.

This repository contains the for firmware for the CAN IoT device boards based on the AVR ATmega328P (B) MCU.

It implements the custom CANIOT protocol, which is a simple protocol base on CAN. It enables a Gateway to received telemetry from the device, send generic commands and make essential configuration. Full implementation and documentation of the protocol is available at caniot-lib.

This firmware also runs a custom RTOS, which provides simple features like cooperative multitasking, synchronization primitives, workqueues, low-level drivers and more. Full implementation and documentation of the RTOS is available at AVRTOS.

This firmware does not implement any specific device logic, but allow a gateway to control several types of devices, such as garage door, shutters, heaters and more through the CANIOT protocol.

Required features (TODO)

  • I2C bus discovery
  • Jitter detection
  • Reboot counter
  • Implement CANIOT "telemetry on change" for Class 1 Tiny BSP
  • Test firmware to impersonate another device/class
  • Serial protocol over CAN to send text messages
  • 1W: read temperature sensors serial number dynamically
  • Attribute for OS monitoring
    • tasks count, max stack usage, irq count, thread switch count, idle time percentage ...
  • Implement device inhibit
  • Make TCN75 temperature read asynchronous (not in telemetry handler)
  • Remove __PACKED structures from buffer union in caniot_frame to make code portable

Boards

Following boards are supported:

  • V1 (documentation): First prototype (used for garage door controller and outdoor alarm controller)
  • Tiny (documentation): Second prototype (used for heating controller and shutters controller)
Board MCU Controllable pins Devices/Drivers support CANIOT Class
V1 ATmega328P(B) 8 TCN75
DS18S20
CLASS0
Tiny rev A schematic ATmega328P(B) 19 TCN75(A)
DS18S20
PCF8574(A)
CLASS1
Tiny rev B ATmega328P(B) 19 TCN75(A)
DS18S20
PCF8574(A)
CLASS1

Applications:

All features

  • Boards
    • v1
    • Tiny
  • MCU Support
    • ATmega328P
    • ATmega328PB
  • Communication
    • CAN
    • CANIOT protocol
  • Device support
    • TCN75 (A) (I2C)
    • DS18S20 (one wire)
    • PCF8574 (A) (I2C)
  • More high-level features
    • GPIO Pulse support
    • Heaters
    • Shutters
    • Grid power presence detection

Project structure

├── docs : documentation
├── include
├── lib : external libraries
│   ├── AVRTOS : Custom RTOS for AVR MCUs
│   ├── caniot-lib : Custom CAN application protocol
├── pics
├── res : Ressources (board schematics, ...)
├── platformio.ini : PlatformIO configuration
├── readme.md : This file
├── scripts
└── src : Source code
    ├── bsp : Board support package for supported boards (v1, tiny, ...)
    ├── class : Code specific to a specific CANIOT class (see CANIOT protocol documentation)
    ├── devices : Drivers for supported devices (TCN75, DS18S20, heater, shutter, ...)
    ├── nodes : Specific code to achieve device role (garage door, heater, ...)

Build the firmware

PlatformIO for VSCode is required to build the firmware. Then simply select the application you want to build and press the build button.

Bootloader

Minicore bootloader is required.

Flash the firmware

Flash with PlatformIO or avrdude.

Monitor

With pyserial miniterm: python3 -m serial.tools.miniterm /dev/ttyACM0 500000. Exit with Ctrl + T then Q

Or screen: screen /dev/ttyACM0 500000. Exit screen with shortcuts : Ctrl + A and Ctrl + \ meaning (AltGr + 8), then y.


Devices

  • Garage Door Controller
  • Outdoor Alarm Controller
  • Heating Controller
  • Shutters Controller

Expected result with Outdoor Alarm Controller (outdated)

Logs

ROM = 28 bc 49 9c 32 20 1 83: DS18B20
===== k_thread =====
C 0x045C READY   C ____ : SP 21/110:0x016D
A 0x0470 READY   C ____ : SP 21/160:0x020D
W 0x0484 READY   C ____ : SP 21/128:0x02D1
M 0x0498 READY   C ____ : SP 0/250:0x06D4
I 0x04AC READY   P ____ : SP 21/59:0x0248
name    = AlarmController
cls/dev = 0/3
version = c8

00:00:00 [0.026 s] : [ c5 ] Telemetry Response [24] 0x18 (cls=C0 sid=D3) : ep-0 / 00 00 f4 01 00 00 46 00 
[C] CANARIES until @0133 [found 50], MAX usage = 59 / 109 + 1 (sentinel) 
[A] CANARIES until @01EE [found 127], MAX usage = 32 / 159 + 1 (sentinel)
[W] CANARIES until @0293 [found 64], MAX usage = 63 / 127 + 1 (sentinel)
[M] CANARIES until @0620 [found 68], MAX usage = 181 / 249 + 1 (sentinel)
[I] CANARIES until @0220 [found 17], MAX usage = 41 / 58 + 1 (sentinel)
00:00:16 [16.450 s] : [ c0 ] Command Query [24] 0x18 (cls=C0 sid=D3) : ep-0 / 00 10 00 00 00 00 00 00
00:00:16 [16.452 s] : alarm: inactive -> observing
00:00:16 [16.454 s] : [ c5 ] Telemetry Response [24] 0x18 (cls=C0 sid=D3) : ep-0 / 04 00 f4 01 00 00 7d 00
00:00:21 [21.571 s] : [ c0 ] Command Query [24] 0x18 (cls=C0 sid=D3) : ep-0 / 00 01 00 00 00 00 00 00
00:00:21 [21.574 s] : [ c5 ] Telemetry Response [24] 0x18 (cls=C0 sid=D3) : ep-0 / 05 00 f4 01 00 00 7d 00
00:00:22 [22.430 s] : [ c0 ] Command Query [24] 0x18 (cls=C0 sid=D3) : ep-0 / 00 04 00 00 00 00 00 00
00:00:22 [22.439 s] : [ c5 ] Telemetry Response [24] 0x18 (cls=C0 sid=D3) : ep-0 / 07 00 f4 01 00 00 7d 00
00:00:25 [25.043 s] : [ c0 ] Command Query [24] 0x18 (cls=C0 sid=D3) : ep-0 / 00 00 00 00 00 00 00 00
00:00:25 [25.046 s] : [ c5 ] Telemetry Response [24] 0x18 (cls=C0 sid=D3) : ep-0 / 07 00 f4 01 00 00 7d 00
00:00:26 [26.184 s] : [ c0 ] Command Query [24] 0x18 (cls=C0 sid=D3) : ep-0 / 00 00 00 00 00 00 00 00
00:00:26 [26.187 s] : [ c5 ] Telemetry Response [24] 0x18 (cls=C0 sid=D3) : ep-0 / 07 00 f4 01 00 00 7d 00
00:00:27 [27.013 s] : [ c0 ] Command Query [24] 0x18 (cls=C0 sid=D3) : ep-0 / 00 00 00 00 00 00 00 00
00:00:27 [27.016 s] : [ c5 ] Telemetry Response [24] 0x18 (cls=C0 sid=D3) : ep-0 / 07 00 f4 01 00 00 7d 00
00:00:28 [28.133 s] : [ c0 ] Command Query [24] 0x18 (cls=C0 sid=D3) : ep-0 / 00 00 00 00 00 00 00 00
00:00:28 [28.136 s] : [ c5 ] Telemetry Response [24] 0x18 (cls=C0 sid=D3) : ep-0 / 07 00 f4 01 00 00 7d 00
[C] CANARIES until @0132 [found 49], MAX usage = 60 / 109 + 1 (sentinel)
[A] CANARIES until @0194 [found 37], MAX usage = 122 / 159 + 1 (sentinel)
[W] CANARIES until @0293 [found 64], MAX usage = 63 / 127 + 1 (sentinel)
[M] CANARIES until @061D [found 65], MAX usage = 184 / 249 + 1 (sentinel)
[I] CANARIES until @0220 [found 17], MAX usage = 41 / 58 + 1 (sentinel)

Capability mask

bit(s) name description
0 watchdog support yes/no
1 dfu support yes/no
2 release yes/no
3:4 microcontroller 0: atmega328p, 1: atmega328pb
5:6 DS18B20 support 0: no, 1,2,3: DS max count
7:8 TCN75 support 0: no, 1: TCN75, 2: TCN75A
9:10 heaters support 0: no, 1,2,3: max count
11:12 shutters support 0: no, 1,2,3: max count
13:14 relays support 0: no, 1,2,3: max count
15:16 optocoupler support 0: no, 1,2,3: max count

Devops

Build docker image:

docker build -t devops/fedora-pio-toolchain -f scripts/Dockerfile .

Run docker image:

docker run --entrypoint /bin/bash -it devops/fedora-pio-toolchain

Run pio within the docker image:

docker run -it devops/fedora-pio-toolchain 

Documentation

Create python virtual environment:

python3 -m venv venv

Install mkdocs:

pip install mkdocs-material

Run mkdocs:

mkdocs serve

Ressources (to cleanup)

caniot-device's People

Contributors

lucasdietrich avatar

Stargazers

 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.