OpenWrt Forum Archive

Topic: GliNet micro router RTC update

The content of this topic has been archived on 15 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Started here originally updating a TP-Link Microrouter TL-WR710N 8/32 device.  Its been running fine now for a few months.

Recently purchased the GLiNet Microrouter model 6416A with 16/64. 

It has more play space and much smaller than the TL-WR710N.

I have updated it to most current release of OpenWRT.

http://wiki.openwrt.org/toh/gl-inet/gl-inet

Purchased the smallest RTC clock that I could find for it. 

Connected the RTC clock to VCC (5VDC), GND, GPIO 20(SDA) and GPIO 19(SDL).

It is a Arduino I2C RTC DS1307 AT24C32 Real Time Clock module+board for AVR ARM PIC.

http://www.sainsmart.com/arduino-i2c-rt … m-pic.html

It was easy to install on the GLiNet Microrouter.

dmesg shows:

[   12.350000] Custom GPIO-based I2C driver version 0.1.1
[   12.350000] i2c-gpio i2c-gpio.0: using pins 20 (SDA) and 19 (SCL)


Looking now for ic2-tools and noticed that in the most current build the tools are not present.

Any suggestions relating to how I can implement / use this RTC clock in my new GLiNet Microrouter?

I am doing an automation thing with the device via using LUA / serial port chit chat and need to have an RTC clock.

Trying to keep it simple and like that I have 64Mb to play with.

(Last edited by petey on 13 Nov 2015, 18:25)

I am to the point of seeing the RTC clock with i2c-tools.

Kernel messages:
[  463.270000] Custom GPIO-based I2C driver version 0.1.1
[  463.270000] i2c-gpio i2c-gpio.0: using pins 20 (SDA) and 19 (SCL)
[  502.150000] i2c i2c-0: new_device: Instantiated device ds1307 at 0x68

# i2cdetect -y 0
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: 50 -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- 68 -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

I have installed kmod-rtc-ds1307.

I get an error though with:

insmod rtc-ds1307

Failed to find rtc-ds1307. Maybe it is a built in module ?

(Last edited by petey on 13 Nov 2015, 18:20)

Got it working this afternoon. 

Author / OpenWRT Tweaker Guru Cezary Jackiewicz updated the modules in the libs section of the firmware.

I did not install ic2-tools as it is not necessary to look and verify.  The ic2-tools are installed via an archived tools directory from a previous version of OpenWRT firmware.

root@ICS-GLiNet:~# opkg install kmod-i2c-gpio-custom Installing kmod-i2c-gpio-custom (3.18.23-2) to root...
Downloading
hxxp://dl.eko.one.pl/chaos_calmer/ar71xx/packages/kmod-i2c-gpio-custom_3.18.23-2_ar71xx.ipk.

Multiple packages (kmod-i2c-core and kmod-i2c-core) providing same name marked HOLD or PREFER. Using latest.

Installing kmod-i2c-core (3.18.23-1) to root...
Downloading
hxxp://dl.eko.one.pl/chaos_calmer/ar71xx/packages/kmod-i2c-core_3.18.23-1_ar71xx.ipk.
Installing kmod-i2c-gpio (3.18.23-1) to root...


Downloading
hxxp://dl.eko.one.pl/chaos_calmer/ar71xx/packages/kmod-i2c-gpio_3.18.23-1_ar71xx.ipk.
Installing kmod-i2c-algo-bit (3.18.23-1) to root...
Downloading
hxxp://dl.eko.one.pl/chaos_calmer/ar71xx/packages/kmod-i2c-algo-bit_3.18.23-1_ar71xx.ipk.
Configuring kmod-i2c-core.
Configuring kmod-i2c-algo-bit.
Configuring kmod-i2c-gpio.
Configuring kmod-i2c-gpio-custom.

root@ICS-GLiNet:~# insmod i2c-gpio-custom bus0=0,20,19

root@ICS-GLiNet:~# opkg install kmod-rtc-ds1307 Multiple packages (kmod-rtc-ds1307 and kmod-rtc-ds1307) providing same name marked HOLD or PREFER. Using latest.
Installing kmod-rtc-ds1307 (3.18.23-1) to root...
Downloading
hxxp://dl.eko.one.pl/chaos_calmer/ar71xx/packages/kmod-rtc-ds1307_3.18.23-1_ar71xx.ipk.
Multiple packages (kmod-i2c-core and kmod-i2c-core) providing same name marked HOLD or PREFER. Using latest.
Configuring kmod-rtc-ds1307.

root@ICS-GLiNet:~# insmod rtc-ds1307
module is already loaded - rtc-ds1307

root@ICS-GLiNet:~# echo ds1307 0x68 > /sys/bus/i2c/devices/i2c-0/new_device

root@ICS-GLiNet:~# hwclock -s
root@ICS-GLiNet:~# hwclock -w
root@ICS-GLiNet:~# hwclock -r

Tue Feb 25 03:07:46 2014  0.000000 seconds

Next steps are scripting it to autostart and configuring one 1-wire temperature sensor which I can install on the little RTC clock board.

Here is what I did to autostart the RTC clock on the GLiNet router.

Auto starting hardware clock

1 - Configure module creating a file called /etc/modules.d/99gpio-i2c-rtc

i2c-gpio-custom bus0=0,20,19
rtc-ds1307

2 - Create a script, /etc/init.d/rtc-driver to load the device driver and set the time.

#!/bin/sh /etc/rc.common
logger "Setup i2c RTC"
echo ds1307 0x68 > /sys/bus/i2c/devices/i2c-0/new_device
if hwclock | grep 'Jan' | grep -q 2000 ; then
  logger "RTC appears to have a flat battery..."
else
  logger "RTC set hwclock"
  hwclock -s
fi

3 - Create a symlink to #2

ln -s /etc/init.d/rtc-driver /etc/rc.d/S11rtc-driver

4 - reboot, ssh to device and type hwclock at prompt to validate.

OpenWrt Chaos Calmer 15.05 (r47466)
Build time: 2015-11-13 19:55 CET

root@ICS-GLiNet:~# hwclock
Sat Nov 14 11:21:39 2015  0.000000 seconds
root@ICS-GLiNet:~#

Taking advantage of the 1-Wire pins built in to the RTC clock soldered on a DS-18B20 1-Wire temperature sensor.

Using the above methodology works great.  Here are my steps.

Part-1

Installation of software packages for installation of 1-WIre DS-18B20,

1 - opkg update

2 - # opkg install kmod-w1 kmod-w1-master-gpio kmod-w1-gpio-custom

3-# insmod w1-gpio-custom bus0=0,18,0

4- echo "w1-gpio-custom bus0=0,18,0" > /etc/modules.d/59-w1-gpio-custom

5 - opkg install kmod-w1-slave-therm

6 - cat /sys/bus/w1/drivers/w1_slave_driver/*/w1_slave

d4 01 4b 46 7f ff 0c 10 6f : crc=6f YES
d4 01 4b 46 7f ff 0c 10 6f t=29250

* crc=6f YES means its working and 29250 is the temperature in Celsius

7 - awk -F= '/t=/ {printf "%.02f\n", $2/1000}' /sys/bus/w1/drivers/w1_slave_driver/*/w1_slave

29.25

Very useful information here--please keep it coming. I linked to this thread from the GPIOs section of the GL.iNet page in the Table of Hardware.

(Last edited by lizby on 15 Nov 2015, 20:52)

Thank you lizby.

Yup; I am amazed with the options available off the shelf on the GL.iNet microuter.  I have posted on the GL.iNet forum too.

Next trying to learn and use LUA a bit.  I did test out the temperature stuff with a Python script and it works fine.  I am trying to get a handle on the Lua scripting stuff.  Baby steps now chit chatting out the serial port for some automation stuff.

Everything is out there on Internetlandia; finding it easy by searching. 

Here is a little test micro python script that works fine for the temperature sensor.  Always here have played with 1-Wire sensors.  Geez didn't even know that a micro python existed until I downloaded and installed it.

#!/usr/bin/micropython
def gettemp(id):
  try:
    mytemp = ''
    filename = 'w1_slave'
    f = open('/sys/bus/w1/devices/' + id + '/' + filename, 'r')
    line = f.readline() # read 1st line
    crc = line.rsplit(' ',1)
    crc = crc[1].replace('\n', '')
    if crc=='YES':
      line = f.readline() # read 2nd line
      mytemp = line.rsplit('t=',1)
    else:
      mytemp = 99999
    f.close()

    return int(mytemp[1])

  except:
    return 99999

if __name__ == '__main__':

  # Script has been called directly
  id = '28-0000025f52c2'

# As an integer
tempDS18B20 = gettemp(id)/float(1000)
tempf = 9.0/5.0 * tempDS18B20 + 32

# As a String
tempDS18B20 = '{:.3f}'.format(gettemp(id)/float(1000))

print (tempDS18B20,"°C")
print (tempf, "°F")


root@ICS-GLiNet:/www# micropython ds18b20b.py
29.687 °C
85.325 °F

(Last edited by petey on 16 Nov 2015, 00:49)

The discussion might have continued from here.