Dan-in-CA / SIP

A highly customizable DIY irrigation/sprinkler controller based on Raspberry Pi
358 stars 156 forks source link

language OSPi #36

Closed martinpihrt closed 10 years ago

martinpihrt commented 10 years ago

Hello, I would like to ask you to add support for languages ​​(such as language folder and en-GB.ini, cs-CZ.ini ....). I try to keep your system up to date on my website (http://www.pihrt.com/elektronika/248-moje-rapsberry-pi-zavlazovani-zahrady) in Czech language. I added in OSPi some extensions (SMS, e-mail, A/D temp/volt ...) and is a crazy job to translate everything from scratch with every version change from 1.8.3 to 2.0 and later... I would support that language was not a problem when you've released a new version the future. I have already tried to do for Czech http://www.getlocalization.com/accounts/login/?next=/OpenSprinkler/ # and once the support for the language I do translation in CZ. I would like to thank you for the great work OSPi and applications for tablet (salbahra). I apologize for my English (google translator). Thanks MaPi

salbahra commented 10 years ago

I noticed you posted a getlocalization link and I wanted to let you know that project is for the mobile app. More specifically, it's for the PHP web app which isn't in active development anymore. Since the strings are quite similar between the native app and the web app I will move over the compatible translations.

As for OSPi, it currently isn't localizable. I guess part of your question is can support be added? If so, I think now that the theme changed and uses Web.py, i18n support can be extended quite easily. If you would like to submit a pull request I am sure Dan would be amenable to that.

Update: I have merged the localization to the native app, available here: http://www.getlocalization.com/Sprinklers/ I will submit this to the app stores once you have a chance to look at it. There are a few strings not translated yet.

Thanks

martinpihrt commented 10 years ago

I would like to use both (OSPI and mobile) translate to czech. I think that would be found by somebody else what would have translated into your own language

Yes, I wanted to translate mobile application (I thought that this was the https://github.com/salbahra/OpenSprinkler-Controller). Thank you for the link: http://www.getlocalization.com/Sprinklers/ I look at it ...

OSPI Yes, if I may ask to add support for i18n localization for other languages thank you

Dan-in-CA commented 10 years ago

I agree that localization support should be added. I will work on extracting the strings that need translation.

martinpihrt commented 10 years ago

Thank you Dan for your support localization in OSPi. I think it also is not resolved in time synchronization internet failure (time and that watering will be wrong). If no Internet conection (system RasPi has after restart bad time - fake time) NTP no run. Therefore, it is in sync with the first OSPi RTC time and next run timing loop

Please support code end on OSPi.py: if name == 'main': rtc = 'rtctime.sh' cmd = '/bin/sh %s' % rtc os.system(cmd) app = OSPi_app(urls, globals()) gv.srvals = [0]*(gv.sd['nst']) set_output() thread.start_new_thread(timing_loop, ()) app.run()

file rtctime.sh: if [ "$(sudo i2cdetect -y 1 | grep ' 68 ')" ]; then echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device sudo hwclock -s else echo "No find RTC device I2C adr. 0x68" fi exit 0

thank you

Dan-in-CA commented 10 years ago

Hi Martin,

Regarding the use of the real time clock (RTC), it can be done within the operating system rather than by adding code to ospi.py.

Here are instructions I have been working on for the Wiki:

Introduction

This is a look at how to keep the time settings on the OpenSprinkler Pi and Bo boards accurate with or without a reliable internet connection including setup and use of the Real Time Clock (RTC) also known as a Hardware Clock.

The operating systems of Raspberry Pi (OSPi) and Beagle Bone Black (OSBo) versions of OpenSprinkler have different pre-installed features for handling time. Both operating systems include a clock known as the system clock. The system clock must be set to the current time whenever the unit is booted up and has no way of keeping track of time when it is powered off. The Raspbian operating system, standard on the OSPi, comes with the ntp program whereas Ubuntu used on the OSBo includes the ntpdate program. The difference is that the ntpdate program on the OSBo sets the system clock from the internet at boot and that’s all it does. The ntp program on the Pi sets the system clock at boot and continues to run in the background updating the system clock periodically. The ntp program also calculates the drift rate of the system clock and adjusts for that. It can even be configured to use the time setting from the RTC when there is no internet connection.

If your setup has a reliable internet connection that is always on, this may be all you need.

You can easily add the ntp program to the the OSBo from the command line with:

sudo apt-get install ntp

You can also remove the ntpdate program from the OSBo with:

sudo apt-get remove ntpdate

This is optional. It probably doesn’t cause any problems to leave it installed.

Because the OSPi and OSBo are designed to run continuously, having a program that only runs at boot is not particularly useful.

Linux systems often include a Hardware Clock to maintain the time setting when the system is powered off. The RTC on the OSPi and OSBo boards provides a hardware clock that has a battery to keep it running even when the unit is powered off. Most Linux distros include software to support the hardware clock. This is true of both Raspbian and Ubuntu.

Both systems include a program called “hwclock” which is used for managing time settings of the RTC and can work with the system clock. It can, among other things, set the RTC from the system clock. The RTC is not considered to be very accurate because, like the system clock, it will slowly gain or loose time. This is known as systematic drift but it occurs at a fairly steady rate. The hwclock program can measure the rate of systematic drift and make adjustments to the RTC to compensate for it much like the ntp program does for the system clock.

If you want to make use of the RTC and have it maintain an accurate time setting, follow the steps below. Once things are set up, the OSPi or OSBo should be able to keep accurate time even without a steady internet connection.

Here’s what needs to be done:

  1. Make sure the RTC is enabled. It is by default on Ubuntu but not on Rasbian.
  2. Prepare a couple of scripts to help the hwclock program to keep the RTC time setting accurate. See steps 6 & 7.
  3. Configure the ntp program to use the time setting from the RTC when there is no internet connection. See step 8.

As mentioned above Ubuntu on the OSBo is pre-configured to use a hardware clock. If you are setting up an OSPi, you will need to do some additional steps.

  Enabling the RTC on the Raspi

Note: If you are using an OSBo, skip to step 5

With the Pi connected to the OSPi board and powered on, (see instructions on Rayshobby website):

  1. Edit /etc/modprobe.d/raspi-blacklist.conf :

    sudo nano /etc/modprobe.d/raspi-blacklist.conf

    comment out the line “blacklist i2c-bcm2708” by adding a “#” at the start of the line.

    The file should look like this:

    blacklist spi and i2c by default (many users don't need them)

    blacklist spi-bcm2708

    blacklist i2c-bcm2708

    cntl o

    to save,

    cntl x

    to exit the editor

  2. Edit /etc/modules:

    sudo nano /etc/modules

    add the following lines:

    i2c-bcm2708 i2c-dev

  3. Edit /lib/udev/hwclock-set:

    sudo nano /lib/udev/hwclock-set

    change both occurrences of “—systz” to "—hctosys". (without the quotes)

  4. Create the script /etc/init.d/rtcdev:

    sudo nano /etc/init.d/rtcdev

    add the following content.

    ! /bin/sh

    BEGIN INIT INFO

    Provides: rtcdev

    Required-Start: kmod

    Required-Stop:

    X-Start-Before: hwclock

    X-Stop-After:

    Default-Start: S

    Default-Stop:

    Short-Description: creates RTC device

    END INIT INFO

    . /lib/lsb/init-functions

    case "$1" in start) if [ ! -e /dev/rtc0 ]; then log_action_msg "Creating RTC device..." echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device fi ;; restart|reload|force-reload) echo "Error: argument '$1' not supported" >&2 exit 3 ;; stop)

    No-op

       ;;

    *) echo "Usage: $0 start|stop" >&2 exit 3 ;;

    esac

    exit 0

    Make the script file executable with:

    sudo chmod 755 /etc/init.d/rtcdev

    Enable the script:

    |sudo update-rc.d rtcdev defaults|

    |sudo update-rc.d rtcdev enable|

    |Reboot the Pi:|

    |sudo reboot|

|5. Check that the RTC is working:|

|sudo hwclock –r|

|This should return the RTC’s time setting.|

|You can also check the system clock with:|

|date|

|If the system clock is correct but the RTC is not, you can set the
RTC from the system clock with:|

|sudo hwclock –w|

|If they are both wrong, or you don’t have an internet connection,
||See “Setting the time manually” below|

|6. Create a cron script to calibrate the RTC from the system clock once a week:|

|sudo nano /etc/cron.weekly/calrtc|

|the file should look like this:|

#!/bin/sh

hwclock -w

This sets the RTC from the system clock and causes the hwclock
program to re-calculate systematic drift. This script should only be
used if the OSPi has an internet connection most of the time. If
not, you should occasionally set the RTC manually. See below.

Make the script executable with:

sudo chmod 755  /etc/cron.weekly/calrtc

Having the script located in the /etc/chron.weekly/ directory will
cause it to be automatically run once a week. No other settings are
needed.
  1. Create a cron script to adjust the RTC for drift each day:

    |sudo nano /etc/chron.daily/adjrtc|

    |Add the following lines.|

    !/bin/sh

    hwclock –adjust

    Make the script executable with:

    sudo chmod 755 /etc/cron.daily/adjrtc

    This will cause hwclock to adjust the RTC using the calculated systematic drift once a day.

  2. configure the ntp program to use the time setting from the RTC if there is no internet connection:

    sudo nano /etc/ntp.conf

    Find the part of the file where several lines start with “server…”. Just after the last “server…” line add:

    server 127.127.1.1 fudge 127.127.1.1 stratum 12

    after saving the file and exiting the editor, reboot the system and test with

    ntpq –p

    You should see something like:

     remote           refid      st t when poll reach   delay  

    offset jitter

    -sisdb01.muskego 173.255.240.184 3 u 46 64 3 76.189 86577.7 0.480 *tock.usshc.com .GPS. 1 u 47 64 3 84.782 86648.7 0.211 +tick.eoni.com 216.228.192.69 2 u 47 64 3 72.181 86652.2 2.272 +clock.trit.net 216.218.192.202 2 u 47 64 3 33.589 86648.7 0.174 LOCAL(0) .LOCL. 5 l 112 64 2 0.000
    0.000 0.001

    The last line starting with LOCAL(0) is the RTC as a time server. It will only be used as a last resort by the ntp program. Actually the program that does the work is called ntpd which is a daemon that runs in the background.

    Your system should now maintain an accurate system time and hardware clock. In the event of a prolonged internet outage, the RTC will be used to keep the time “up to date”.

    Setting the time manually
    
         you can use the hwclock program to set the RTC to a
         manually entered time and date with:

    sudo hwclock --set --date="yyyy-mm-dd hh:mm:ss"

    example date string, "2011-08-14 16:45:05"

         To set the system clock manually use:

    |sudo date --set="yyyy-mm-dd hh:mm:ss"|

    example:

    |sudo date --set="|2011-08-14 16:45:05"

    hint: To set the date as accurately as possible, enter a time a few seconds in the future and tap the Enter key when your watch/clock reaches that time.

For full details of the ntp program see:

http://doc.ntp.org/4.2.0/index.html#conf

To use ntpdate:

sudo service ntp stop

sudo ntpdate |pool.ntp.org|

|sudo service ntp start|

||

On 6/11/2014 12:23 PM, Martin Pihrt wrote:

Thank you Dan for your support localization in OSPi. I think it also is not resolved in time synchronization internet failure (time and that watering will be wrong). If no Internet conection (system RasPi has after restart bad time - fake time) NTP no run.

Therefore, it is in sync with the first OSPi RTC time and next run
timing loop

Please support code end on OSPi.py: if name == 'main': rtc = 'rtctime.sh' cmd = '/bin/sh %s' % rtc os.system(cmd) app = OSPi_app(urls, globals()) gv.srvals = [0]*(gv.sd['nst']) set_output() thread.start_new_thread(timing_loop, ())

app.run()

file rtctime.sh:

!/bin/sh -e

rtctime

real time (RTC) DS 1307 adr 0x68 .

setup time sync RPi - RTC DS1307

if [ "$(sudo i2cdetect -y 1 | grep ' 68 ')" ]; then echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device sudo hwclock -s else echo "No find RTC device I2C adr. 0x68" fi

exit 0

thank you

— Reply to this email directly or view it on GitHub https://github.com/Dan-in-CA/OSPi/issues/36#issuecomment-45787502.

martinpihrt commented 10 years ago

Yes, that's exactly what I needed ... thank you very much

Dan-in-CA commented 10 years ago

Hi Martin,

I just want to let you know that I have not forgotten about the translation for OpenSprinkler Pi. I have been busy fixing bugs in the software but have already added most of the markup for i18n support in the UI. It should be possible to prepare a translation template for you in the next week or so.

Dan

martinpihrt commented 10 years ago

Hi Dan, thank you for the information. Regards Martin

Dan-in-CA commented 10 years ago

Hi Martin,

There is a new file in the i18n directory in my GitHub repository named OSPi_messages.pot. It is a translation template for the new OSPi UI.

It contains lines of text like this:

: gv.py:96 = location of text in project files

msgid "System name" = English text msgstr "" = put your translation here

You just need to fill in the translations in each "msgstr" line matching the English in the "msgid" line.

When you are done, send me the file and I will do some further processing.

Let me know if you have any questions. Dan

martinpihrt commented 10 years ago

Hi Dan, thank you for your work ... will gradually start to translate and then send the file ... Thank you Martin

martinpihrt commented 10 years ago

Hi Dan, I have OSPi new actual version 2.0.3 with file I18N OSPI_mesages.pot with translate to Czech language. But web OSPi is in English. Need I something else to install for translate to CZ? Thank you Martin.

Dan-in-CA commented 10 years ago

Martin,

There is more that needs to be done. I have been traveling for 3 days and not able to work on it. I will do the nest steps in a few days.

Dan

martinpihrt commented 10 years ago

Ok. thak you Dan

martinpihrt commented 10 years ago

Thank you Dan