Test Kamery

					

Kitesurfing Rules of the Road

Original posters and the text files in English, Korean and Chinese are attached below.

You can help by translating them from English to other languages.

Kitesurfing Rules of the Road

  1. Before launching a kite from the beach, one must be sure that it does not create any danger, not only for other riders but also for other people on the launching spot. In addition, the fact that the kite can drag a few dozen meters during launching this should be taken into account. A rider launching his kite on the beach gives way to anybody around him.
  2. Give way to riders entering the water. Being on land with an inflatable kite is more hazardous than being on water. Always allow others to enter the water even if this means having to take another turn before being able to return to the beach.
  3. When passing one another, the upwind rider must put his kite up and downwind rider must put his kite down.
  4. Give way to riders who are not in control of their equipment. You should give space to riders without their board or who look less in control (students).
  5. If two riders are on colliding course, rider riding right hand forward has the priority. If rider is riding switch (toe side edge), he has left hand forward of course.
  6. When overtaking, faster kiter must not obstruct or impede the slower kiter. Faster kiter must keep clear by a suitable distance, either windward (upwind) or leeward (downwind).
  7. The downwind rider has the priority. The upwind rider keeps out of the way of the downwind rider.
  8. Rider riding a wave has always the priority.
  9. The multiperson meetings increase the risk of collisions and should be avoided. It concerns especially beginners. Seeing that in a moment the multiperson meeting will take place and having doubts whether it is safe, the best way is to make a U-turn on the opposite course. If there is no place for that, just stop, set your kite in the zenith and wait until the situation is cleared.
  10. Give way to other water users over. Remember, even if it is your right of way, it is your responsibility to avoid collision at all costs and to help keep kitesurfing safe and respect as a watersport.

Python MinimalModbus + SHT20 Modbus RTU RS485 Temperature and humidity sensor

#! /usr/bin/python
import minimalmodbus
import time
# Set the value minimalmodbus.CLOSE_PORT_AFTER_EACH_CALL=True 
# immediately after import minimalmodbus
minimalmodbus.CLOSE_PORT_AFTER_EACH_CALL=True

# default slave address = 1
instr = minimalmodbus.Instrument(port='/dev/ttyUSB0', slaveaddress=1)
instr.serial.baudrate = 9600
instr.serial.parity  = "N"
instr.serial.timeout  = 0.8
#instr.debug = True
print(instr)

"""
read slave address, baud rate, temp. correction, hum. correction
"""
print(instr.read_registers(257, 4,functioncode=3))

"""
change of the slave address 
the change will take effect after reboot only! 
it is possible to continue using the old address till reboot
"""
slaveNewAddress = 5
#instr.write_register(257, slaveNewAddress, functioncode=6)

"""
change of the speed - take effect imediatelly
the change will take effect after reboot only! 
it is possible to continue using the old address till reboot
"""
slaveNewBaudrate = 9600
#instr.write_register(258, slaveNewBaudrate, functioncode=6) 

# read slave address, baud rate, temp. correction, hum. correction
print(instr.read_registers(257, 4,functioncode=3)) 

time.sleep(1)

while 1:
    try:
        print instr.read_registers(1,2, functioncode=4) # read temp and hum (list)
        print instr.read_register(1,1, functioncode=4) # read temp 
        print instr.read_register(2,1, functioncode=4) # read hum 
    except minimalmodbus.NoResponseError:
        print("No Response Error")
    time.sleep(1)
root@danfoss:/home/pi/danfoss# sudo pip install -U minimalmodbus
Collecting minimalmodbus
  Downloading https://files.pythonhosted.org/packages/6c/d5/77d42e8a0b73da2b5f97acd91900ac50e303b4cb959f76350cfbb38e05a0/minimalmodbus-1.0.2-py2.py3-none-any.whl
Requirement already up-to-date: pyserial>=3.0 in /usr/local/lib/python2.7/dist-packages (from minimalmodbus)
Installing collected packages: minimalmodbus
  Found existing installation: MinimalModbus 0.7
    Uninstalling MinimalModbus-0.7:
      Successfully uninstalled MinimalModbus-0.7
Successfully installed minimalmodbus-1.0.2
root@danfoss:/home/pi/danfoss# 

Description of the module here

Power consumption (kWh) monitoring using node-red and influxDB

I have got nice 3phase 30(100)A four wire RS485 MODBUS Din Rail watt meter from Aliexpress (US $35.76) (max. baud rate is possible to set to 9600). I am able to read values using USB-RS485 adapter + Raspberry pi and sending data (json) to the mqtt server. So far no problem. Power meter is providing cummulated value (the same value you can read on the display).

At the first beginning I was sending the data in to the sqlite database using sqlite node-red node. The table was very simple:
(ID, TIMESTAMP, TOTAL_KWH).

The issue starts with the simple question: How to get daily (hourly, weekly, monthly… ) power consumption? Something like:
| 22.7.2019 | 450kWh|
| 23.7.2019 | 320kWh|
| 24.7.2019 | 300kWh|
At the first sight it looks as an easy task, but I ended up with this quite complex query. And as data was growing, the execution of the SELECT was slowing down.

The guys from the nice JOYSFERA server were pointing me to the influxDB. Installation was an easy part thanks to the:
https://www.osradar.com/install-influxdb-ubuntu-18-04-debian-9/

To import existing data in to the influxDB you need a text file with the following structure:

# DDL
CREATE DATABASE mrazirna

# DML
# CONTEXT-DATABASE: mrazirna
# CONTEXT-RETENTION-POLICY:autogen

power value=0.0 1564391161
power value=270.8 1564583065
power value=272.1 1564583462
power value=272.1 1564583542
power value=272.1 1564583621
power value=272.2 1564583701

While preparing the file, note the line ending has to be linux style and if you are importing big data-set, the error messages are displayed on the top of the import screen – you need to scroll up (which was kind of difficult to me to discover).
Now you are ready to import data in to the database:

> influx -import -path=/path/to/the/data/file -precision=s
2019/08/27 22:53:04 Processed 1 commands
2019/08/27 22:53:04 Processed 26934 inserts
2019/08/27 22:53:04 Failed 0 inserts

Next connect the node-red node to the influx database:
https://diyprojects.io/node-red-tutorial-saving-mysensors-measurements-on-influxdb/#.XWWvovxS9B8

When you are preparing data for the influxDB, remember you need to send the same data-type in to the database. In my case the value datatype was float

> show field keys
name: power
fieldKey fieldType
-------- ---------
value    float

It was necessary to writhe following (note *1.0 at the end of the first row) in to the node-red function node (otherwise the string was send to the influxDB)

msg.payload = msg.payload.POWER.toFixed(1)*1.0;
return msg;

The best part is the simplicity of extracting data:

> root@maxbox:/data/new# influx -precision rfc3339
Connected to http://localhost:8086 version 1.7.7
InfluxDB shell version: 1.7.7

> use mrazirna
Using database mrazirna

> select derivative(max(value)) from "power" where time > now()-7d group by time(1d) fill(0) tz('Europe/Prague')
name: power
time                      kWh
----                      ---
2019-08-21T00:00:00+02:00 200.19999999999982
2019-08-22T00:00:00+02:00 199.5
2019-08-23T00:00:00+02:00 202.10000000000036
2019-08-24T00:00:00+02:00 111.80000000000018
2019-08-25T00:00:00+02:00 309.89999999999964
2019-08-26T00:00:00+02:00 222.5
2019-08-27T00:00:00+02:00 278
2019-08-28T00:00:00+02:00 6.5

sqlite SELECT for power consumption reading

So far I have following working code (working with example data)

WITH miniPow as (
	select date(TIMESTAMP,'+1 day') as d, max(TOTAL_KWH) mini
	from power 
	group by date(timestamp)
	)
, maxiPow as (
	select date(TIMESTAMP) as d, max(TOTAL_KWH) maxi
	from power 
	group by date(timestamp)
	)
select maxiPow.d, ROUND(maxi-mini, 1) from miniPow 
 join 
maxiPow
on miniPow.d = maxiPow.d	

Below my first SQL attempt (not really elegant)

WITH consumption AS
  (SELECT date(TIMESTAMP) AS d,
          min(TOTAL_KWH) mi,
          max(TOTAL_KWH) ma
   FROM power
   GROUP BY date(TIMESTAMP)),
     enumerated AS
  (SELECT *,

     (SELECT count(*)
      FROM consumption b
      WHERE a.d >= b.d) AS cnt
   FROM consumption a),
     preenumerated AS
  (SELECT *,

     (SELECT count(*)-1
      FROM consumption b
      WHERE a.d >= b.d) AS cnt
   FROM consumption a)
SELECT strftime('%d.%m.%Y', en.d) AS "období od",
       strftime('%d.%m.%Y', pre.d) AS "období do",
       printf("%.1f", en.ma) AS "počáteční kWh",
       printf("%.1f", pre.ma) AS "koncový kWh",
       printf("%.1f", pre.ma-en.ma) AS "kWh za období",
       (JulianDay(pre.d) - JulianDay(en.d)) AS "počet dnů",
       printf("%.1f", (pre.ma-en.ma)/(JulianDay(pre.d) - JulianDay(en.d))) AS "kWh za den"
FROM enumerated en
JOIN preenumerated pre ON en.cnt = pre.cnt
UNION ALL
SELECT strftime('%d.%m.%Y', min(date(TIMESTAMP))) AS "období od",
       strftime('%d.%m.%Y', max(date(TIMESTAMP))) AS "období do",
       "" AS "počáteční kWh",
       "CELKEM:" AS "koncový kWh",
       printf("%.1f kWh", max(TOTAL_KWH)) AS "kWh za období",
       printf("za %.0f dnů", (JulianDay(max(date(TIMESTAMP))) - JulianDay(min(date(TIMESTAMP))))) AS "počet dnů",
       printf("ø %.1f kWh/den", (max(TOTAL_KWH)-min(TOTAL_KWH))/(JulianDay(max(date(TIMESTAMP))) - JulianDay(min(date(TIMESTAMP))))) AS "kWh za den"
FROM power
Link to example table here

PSF B01 inching ESP-01S relay

I have purchased 2 different WiFi relay modules on Aliexpress, you can find description of my experiments and experiences in this article

5V One Channel Inching /self-locking PSF B01 5V relay using module PSF-B01  (letter B indicates there is WiFi antenna soldered directly on the board (see small white rectangle in the top left corner)

I have found description for ITEAD PSF-B85 only, there is ESP8285 1MB integrated inside the module

  • !!! WARNING !!! you can see many wrong / confusing photos on the internet describing 4 PIN pinholes as Tx, Rx pins
  • !!! WARNING !!! THERE ARE MANY VISUALLY SIMILAR BOARDS TO THIS but different module on the board and different schematics
  • There is another chip/processor yet on this board, called  “Misterious CHIP” 
  • Itead is offering such a device as “1 Channel Inching /self-locking WiFi Wireless Switch 5V 12V”
  • I did buy it on Aliexpress, it came with original Itead SW; Sonoff app eWelink was communicate with the device without any single issue
  • it was possible to update original software using build in OTA to the version 3.0.

Flashing firmware:

I have found this beautiful article about how to flash similar raley board to ESPruna firmware 

  • Solder wires to the pins 22 (TX) and 21 (RX), 20 (GND) (don’t be confused by the Tx Rx description of pinholes in the article). Some people do not solder Tx and Rx and are using POGO pins or wires instead and holding them by hand during the flashing procedure
  • connect them to the Tx, Rx, GND on your USB programmer (ESP Tx <=> USB Rx, ESP Rx <=> USB Tx) 
  • press and hold button B2 (button closer to the green screw terminal)
  • connect the 5V USB power supply
  • release B2 (both red LEDs should to light)
  • now the ESP should be in the programming mode
  • First, I was trying to flash Tasmota firmware (the relay original firmware here ), but the relay was not stable and I didn’t find the way how to set it up properly using “tasmota generic module options”  (see below my setting for ESP 01S relay)” 
  • in the article mentioned above, there is great description how to build the custom ESPurna firmware using Atom+PlatformIO – in my case the first try was returning many errors during compilation
  • The reason was the the ArduinoJson library version 6 was not supported by ESPurna in the time of writing this article (March 2019) . Thanks to the ESPurna forum I have found the solution relatively fast. It was necessary to modify platformio.ini by replacing
lib_deps = ArduinoJson

by

lib_deps = https://github.com/bblanchon/ArduinoJson#v5.13.5

As I wanted to use the DS18B20 to monitor temperature, it was necessary to change the /config/sensors.h  as well and solder wires according to the pictures below 

For ESPurna configuration see the detailed description mentioned in the article or ESPurna wiki.

Flashing binary
esptool.py –port /dev/ttyUSB0 flash_id is showing ESP8285 on the board

ESP-01S relay (ESP8266 5V WiFi relay module)

  • !!! WARNING !!! THERE ARE MANY VISUALLY SIMILAR BOARDS TO THIS RELAY BOARD but different schematics
  • when I have received it from Aliexpress (US $2.09 including ESP-01S), module was not working (I have found other people had the same issue)
  • There are two culprits of this:
    • “CH_PD” is not set to HI (3.3V) as actually required. Usually this is done with a 10K resistor or directly to 3.3V, I have connected CH_PD pin directly to the 3.3V
    • The resistor R2 (10k) which is connected between the terminal GPIO0 to ground. This ensures that the GPIO0 is always pulled to ground, which actually places the ESP-01 in program mode (flashing). After soldering out (removing) R2, the module ran smoothly.

          esptool.py –port /dev/ttyUSB0 write_flash -fs 1MB -fm dout 0x0 sonoff.bin

  • After flashing firmware, I have connected DS18B20 to the GPIO2 as well (see the diagram)
  • Than it was necessary to set up Tasmota as generic module, GPIO0 as Relay1 (21), GPIO2 as DS18x20(4) 
  • OTA upgrade works flawlessly as well 

Retrieving the temperature via HTTP
http://sonoff-ip/cm?user=<USER>&password=<PASS>&cmnd=status%2010

The temperature information will put published by MQTT to the

tele/<SONOFFDEVICE>/SENSOR in the format of:

“Time”:”2018-06-14T07:56:34″,”DS18B20″:{“Temperature”:21.9},”TempUnit”:”C”}

Setting interval at which the sonoff will report it’s status: 

Display current interval: TelePeriod

Set interval: TelePeriod <seconds>

You can change PulseTime by typing “PulseTime 30” in the Console at the Webinterface.