Showing posts with label OHS-GW-2. Show all posts
Showing posts with label OHS-GW-2. Show all posts

Sunday, December 8, 2024

GW Firmware Updates

Recently, there have been a few noteworthy updates to the GW firmware, primarily from the new GW owners. As always, the latest version 1.5.4 is available on the GitHub  releases page.

Here are some key changes:

  • Automatic republishing of zone states to MQTT after reconnecting to the MQTT server. This is useful when updating Home Assistant (HA).
  • The lwIP network library has been updated to stable version 2.2.0.
  • mDNS has been added, both as a client and resolver. The GW is now accessible at http://ohs.local, eliminating the need to search for its DHCP-assigned address.
  • A test alert feature has been added to the web interface, making it easier to verify that all alert paths are properly configured directly from the browser.
  • A new alert path has been introduced. Now, all alerts can be propagated to the MQTT topic /OHS/alert and subsequently consumed in HA.
  • The shell, accessible via USB, now allows for resetting the web admin user to its default settings.

 

 

Sunday, September 6, 2020

Gateway 2.x configuration

Just started to update new page section for gateway 2.x configuration. It can be find in menu on right. It will describe basics terminology for OHS, new shell interface for OHS 2.x gateways and of course a web interface used to configure the functionality.  Currently it is work in progress, but I will try to add all sections that are missing, and finish it as primary guide for new users.

Tuesday, August 25, 2020

DFU - Device Firmware Upgrade

Gateways 2.s have now a new user convenient way of upgrading firmware without any external programmer. As STM32F4xx devices include built in USB DfuSe bootloader, I was wanting to implement such functionality into OHS as well. Since software version 1.2 there is an option in shell interface to boot the device to dfu mode., and then upgrade the firmware directly via USB cable.

DFU tools:

dfu-util  is a simple multi-platform command line tool that can upload binary data directly to flash.

List DFU ready devices via: dfu-util -l

Example output of gateway 2.x, most important is the 'alt=0, name="@Internal Flash  ' descriptor that we gonna use:

Found DFU: [0483:df11] ver=2200, devnum=12, cfg=1, intf=0, path="3-6", alt=3, name="@Device Feature/0xFFFF0000/01*004 e", serial="336A34763437"
Found DFU: [0483:df11] ver=2200, devnum=12, cfg=1, intf=0, path="3-6", alt=2, name="@OTP Memory /0x1FFF7800/01*512 e,01*016 e", serial="336A34763437"
Found DFU: [0483:df11] ver=2200, devnum=12, cfg=1, intf=0, path="3-6", alt=1, name="@Option Bytes  /0x1FFFC000/01*016 e/0x1FFEC000/01*016 e", serial="336A34763437"
Found DFU: [0483:df11] ver=2200, devnum=12, cfg=1, intf=0, path="3-6", alt=0, name="@Internal Flash  /0x08000000/04*016Kg,01*064Kg,07*128Kg", serial="336A34763437"

Flash the firmware via: dfu-util -a 0 --dfuse-address 0x08000000 -D ch.bin

STM32CubeProgrammer is also multi-platform tool but with graphical user interface. One downside is that you need older Java version installed to run it, but once you have it it will work nicely.

DFU howto:

  1. Connect your laptop/PC via USB cable to gateway. Status LED on gateway should change to short rapid flashes.
  2. Open any terminal emulation program like Putty and open serial connection to new enumerated USB device. On Linux it will be ACM0.
  3. In the terminal issue command 'boot dfu'.
  4. The gateway should close the USB connection, terminal will exit, or close, and the status LED will stop blinking.
  5. New USB device should be enumerated as 'STMicroelectronics STM Device in DFU Mode'
  6. Use any of DFU tool to list, connect and to download(in terms of to download a file to a DfuSe device) firmware into gateway.
  7. Reset the gateway via onboard reset button.

 

Saturday, August 22, 2020

Skeches for nodes compatible with OHS 2.x gateway

Recently I have pushed to GitHub new example sketches for the Arduino like remote nodes. These include software modifications, that are needed for the changes made in gateway 2.x software. Hardware part of nodes is still the same for both wired(RS485) and radio(RFM69) nodes.

Changes include:

  • Periodical ping to gateway. OHS 2.x gateway require a ping command from every registered node at lest one in an hour, or it is removed from node list.
  • Arm home. This new functionality is added to authentication mechanism on node, precisely to iButton routine. It works as usual for arm away, that is a quick touch of iButton arms away or disarms the group. When arm home state is required, user needs hold the iButton in probe for more then 1 second. Disarm is same as for arm away, a quick touch only is enough.
  • Authentication key is sent to gateway, and OK / Not OK sound is result of gateway accepting the packet with key. This does not mean that the key is valid and accepted, only that the gateway has received the key. On old node software, the OK / Not OK sound was result of iButton probe reading the iButton correctly or not.
  • New method for CRC signature for RS485 packets.

Repositories with software for nodes compatible with OHS 2.x gateway has name starting with: OHS_2-node

I will add new node examples as I build them.

Wednesday, July 8, 2020

OHS 2.0.4 - final version

There are two changes to final version gateway board for 2.0.4. The PCB remain the same as well as all functionality, but I decided to opt for easier software changes in future.

What I mean is that I changed the MCU on the board from STM32F407 to SMT32F437. It has 64KB more RAM, and hardware accelerated cryptographic unit allowing better support for TLS. F437 allows also a higher nominal frequency, but for now I did not use this option, and left it on 168MHz. But it can come with new firmware if needed.

Second change is to switch to LAN7842A, an updated version of previously used LAN7820A. It has some new functionality which include WOL and Cable sense, which will not be need. But it has also lower power consumption and HP Auto-MDIX support. Basically LAN7842A is recommended for any new design.

On the software part, I've been pretty busy with new version. Porting many of the features of 1.7 gateway into 2.0, and I'm quite happy with it so far. My intention is to create gateway that will not need any other resources to function. 
For example web interface use font awesome for icons, meaning you need connection to internet to see them, as this font has hundreds of kB. But thanks to fontello I managed to create subset of icons that has less then 10kB, witch perfectly fits into 1MB of flash available on MCU. So far, only remote thing that is needed is a SMTP server, in case you wish that gateway should also send email notifications.

Monday, June 8, 2020

OHS 2.0.4

Over past few months I have prepared new version of OHS gateway called simply 2.0.4. It is new iteration of my 2.0 version fixing layout defects and integrating new features. Here are the specifications:

  • STM32F407 with 1GB of flash and 128KB + 64KB CCM of RAM, running at 168MHz.
  • LAN8720A Ethernet PHY with 10/100Mbit.
  • Two step power supply with 12V to 3V8 switching and 3V8 to 3V3 LDO.
  • Battery for RTC CR2032. STM32F407 has on-board RTC.
  • 10 analog (balanced) inputs for PIR, smoke, ...
  • 4G SIM7600x module
  • Radio module for RFM69HCW, or alternatively RFM95.
  • 128KB SPI FRAM.
  • RS485 for wired connections.
  • 2 relays for sirens.
  • 1 tamper zone for enclosure. 
  • Micro USB port.
  • ST-LINK V2 port.
  • 3 LEDs.
The main changes are GSM part, which now sports 4G/LTE modem from SIMCOM SIM7600x, and SPI FRAM with double capacity.

SIM7600x is decision that I've been thinking about for some time. On one hand the module is quite expensive compared to 2G modules, but on the other the 2G is becoming phase out in many countries. It is quite a dilemma, but I decided to invest into module that will have long life expectancy. There are always more difficulties. One is that the hardware needs to be able to speak with 1V8 logic presented on module, which I have solved by adding MOSFET level shifters. And second, that the module is bigger, and I neede to place it on the back of PCB. I have also removed the mini SIM holder, and replaced it with smaller and more up to date micro SIM.
There are several versions of SIM7600 module. One global, most expensive, that is supposed to work in all regions. And the regional ones for Europe, North America, South America, Asia and so on.

FRAM size has doubled for the reason to store some larger data needed conveniently.  First half (64KB) is used as before to keep 4096 log entries for gateway logger. Second half will be available to several new functionalities I plan to add to gateway software. I was also tmepted to add a uSD card, but it is easier to store data on synchronous SPI FRAM, then to access uSD with file system that can be damaged or not present. Not to speak about wiring.

Other changes not so visible are RC circuits on battery and power signals of UPC. These are nicely filtering out the spikes that are sent to gateway, eliminating the need for software compensations. Without them the gateway has wrongly reported AC power OFF signal.
Also there is now a shotky diode, to add polarity protection to RTC battery.

Wednesday, February 5, 2020

Moving forward with OHS2

Just to post latest update about my software progress on OHS version 2. I must say I'm quite happy that I have base functional system with many main system components running on my development board. Namely:
  1. RS485 with new library for Arduino. Sending command and messages with ACKs. All the bits travel back and forth nicely and all timing look good on logic analyzer.
  2. GSM module work well wit accompanied new library for SMT32.
  3. Logging to FRAM.
  4. Relays are fine.
  5. Battery backup storage in SRAM is fine along with ruties.
  6. RTC, although there is now only UTC.
  7. HTTPD is working with static and dynamic html pages and and also POST is functional. Web server now includes pages for system info, zones, groups, nodes, users, keys and log.
With all this I can already use authentication, zone monitoring, groups, and data log.

If someone is interested all the source is in GitHub, and also any contribution is welcome.

Sunday, November 10, 2019

Gateway 2 software updates

I've started to port some of the old libraries written for AVR architecture to new STM32 for new gateway with compatibility in mind. My goal is to still use Arduino based nodes for senors, authentication or relays, just because it's easy to implement new features quickly.

One of my the first and probably most used is RS485 wired library that manages communication over one pair of twisted wires. USART STM32 libraries in ChibiOS are divided to Low Level Driver and API. There are two ready to use USART both of the suitable for different kind of messages. One DMA based somehow preferring fixed messages and second, similar to Arduino serial, with queues and it's based on interrupts. I started to play with both, but I found rather difficult to build logic on top these APIs without changing internals. And because of this, I started with provided serial interrupt driven driver and created new RS485 library for STM32F4 MCU.

Luckily for me, really :), the SMT32F4 has build in logic that fully support my old RS485 library functionality. STM32F4 support not only 9 bit Multi Processor Communication as AVR, but it also provide interrupt on address match. Luckily again, the address register uses 4 bits wide target address, same as my old library, and it verifies 4 least significant bits of incoming header to 4 bits of defined address. Just perfect match, except the STM32 cannot reply the broadcast packets. Which is in reality not a problem for master at all, since only master do send broadcast packets, and every node know master address (0).

But of course writing a new driver for a new architecture was not easy. Thankfully to ChibiOS, I've managed to do so. As side effect, I must say that AVR debugging really sucks, because there is simply none. And once you learn to add breakpoints, stop program at certain line, and see at least some variables and registers, you do not want to go back. But back to new driver, in addition to compatibility between Arduino and STM32, I have also implemented acknowledgment, a feature that was not finalized in old library. And the ACK functionality is automatically performed by LLD on both receiving and sending.

Such ACK functionality also require appropriate changes in AVR side. At first I created incoming and outgoing ACKs directly in sketch. It was functional, but somehow slow, and I was a bit worried about the sketch complexity. And I've decided to update the AVR library according to STM32, I've added driver state and after a few long evenings, I hope I finally manged to do so.

The final packet structure is same to existing one:

-------------~~~~~~~~~~~~~~~~~~~
* A * P * X * D0 ~ D63 * C0 ~ C1
-------------~~~~~~~~~~~~~~~~~~~

- Required part
~ Optional data and CRC

A Address - 4 bits from and 4 bits to address.
   0  is master.
   15 is broadcast to all.
   14 addresses left for nodes.

P Packet definition - 2 bits type and 6 bits length.  
  Types: CMD - Command - user defined general commands value 0 - 6
          DTA - Data - user data length D0 - D63 and CRC S0, S1
          ACK, NACK - flags for data, using signature of data packet
         
X XOR of A and P, for basic transfer safety.

D0 - D63 user data.    
                     
C0 ~ C1  CRC for user data or signature for ACK, NAK. 
Basically it allows two kinds of transfers. First is command mode with value 1 to 63. Command 0 is reserved for ACK functionality. These can be used for some simple repetitive messages and expect predefined action or response. I use, for example, command = 1 to request full node functionality descriptor, i.e. request for registration. When gateway receive valid sensor data from unknown node, it issue CMD 1 to that address to receive its full descriptor.

Second use, is data transfer with maximum length of 64 bytes. It is completely up to the user, what kind of data are transferred. Every data packed is secured by CRC16 and ACK functionality compare these CRC and in case of mismatch invalidates the packet.

On the end I'm happy that new OHS gateway is slowly adopting old functionalities and further improving them.

Tuesday, September 10, 2019

Gateway 2

I did not post too much updates recently, but I was quite busy with new version of gateway. I manage to draw and let fabricate new PCB with 32bit ARM chip as main controller. For the purpose of first design I have shrunk the PCB to 100x100mm, but I have managed to squeeze all component I wanted there. Good news is that I was able to stay on 2 layers, and avoid much more expensive 4 layer PCB. I made the board at pcbway with the cheapest 6/6 method and the quality stays similar to my free boards. I will stay with them for sure.

After realizing that 100x100mm PCB includes all I need, I will most probably stay with this new format. To sum up there is:
  • STM32F407 with 1MB of flash and 128KB of usable free RAM, running at 168MHz.
  • LAN8720A Ethernet PHY with 10/100Mbit.
  • Two step power supply with 12V to 4V switching and 4V to 3V3 LDO.
  • Battery for RTC CR2032. STM32F407 has on-board RTC.
  • 10 analog (balanced) inputs for PIR, smoke, ...
  • 2G SIM800C module
  • Radio for RFM69 or RFM95.
  • 64KB SPI FRAM, bit expensive, but no wait times and blazing speed compared to I2C EEPROM.
  • RS485 for wired connections.
  • 2 relays for sirens.
  • 1 tamper zone for enclosure. 
  • Micro USB port for firmware update and direct console access.
  • ST-LINK V2 port.
  • 3 LEDs.

I guess it will pretty decent update to existing ATMega1284P.

I've made some mistakes during design of the PCB, also I forgot to wire some signals, or got them wired wrong. But, at least, I've managed to get the whole thing running with few cuts of traces here, or jumper wires there. Only hardware part, that I did yet tried, is wireless. After I manage at least initiate, send and receive some test packet I will go for new PCB revision with all corrections and the hardware part may be then ready.

I have already new sketch with addition to mount other then on-board 2G SIM800C. Basically there will be option to have SIM800C mounted, or there will be 2x5P connector to connect other modems like SIM7600 4G modems.