Licznik energii elektrycznej

djack2017
Posty: 686
Rejestracja: pn lis 27, 2017 7:36 am
Kontakt:

Dzięki. Działa. W aplikacji android, na ekranie "rozszerzonym" nie zmienia się ikona - wciąż jest defaultowa.
__________________________________________________________
Specjalizowane oprogramowanie do sterowników Sonoff, Gosund, Blitzwolf, Shelly i innych:
https://djack.com.pl/modules.php?name=Downloads&d_op=viewdownload&cid=54
Awatar użytkownika
o_rany
Posty: 275
Rejestracja: śr lis 14, 2018 5:32 pm
Lokalizacja: Sosnowiec
Kontakt:

pzygmunt pisze: wt maja 07, 2019 7:33 am Jak historia pomiarów zaczyna się od tego miesiąca to tak właśnie będzie przeczytaj mojego posta odnośnie obliczania bieżącego zużycia. W kolejnym miesiącu będzie już ok.
... a czy nie moze byc wartosc wyswietlana powiększona po prostu o wartosc poczatkowa licznika a dane w tabelach zostawic bez zmian?

Teraz jak cos zmienię w ustawieniach cloud to wplywa to na dane w historii.
Wyswietla na wykresie kosmicznie duzy stan (wspisujac stan poczatkowy) przez co mniejsze pomiary sa wrecz niewidoczne.
Kiedy chce wrocic do poprzedniego stanu (wpisuje stan poczatkowy 0) wywala mi na minus (to co juz wspominalem, przy zmianie przelicznika, ze wyglada jakbym produkowal energie).
Awatar użytkownika
pzygmunt
Posty: 18276
Rejestracja: wt sty 19, 2016 9:26 am
Lokalizacja: Paczków
Kontakt:

@o_rany
Aplikacja nie zna wartości początkowej ustawianej ręcznie w cloudzie.
Zmiana tego teraz wymaga zmiany protokołu i aplikacji. Nierealne na tym etapie.

Aby nie było "pików" należy ustawić wartość początkową licznika, a następnie trzeba wyzerować historię. Wtedy wykres będzie OK.
Awatar użytkownika
o_rany
Posty: 275
Rejestracja: śr lis 14, 2018 5:32 pm
Lokalizacja: Sosnowiec
Kontakt:

...no to moze dodac wartosc pczatkowa licznika do historii w osobnej kolumnie a aplikacji powiedziec coby sobie to dodala:)
Awatar użytkownika
pzygmunt
Posty: 18276
Rejestracja: wt sty 19, 2016 9:26 am
Lokalizacja: Paczków
Kontakt:

Nic w tym obszarze nie zmienię. Każda tego typu zmiana przesunie wydanie aplikacji na androida o kilka tygodni.
Wyczyść historię po zmianie wartości początkowej i po sprawie. Przecież to ustawiasz raz i później już tego nie zmieniasz.
Awatar użytkownika
o_rany
Posty: 275
Rejestracja: śr lis 14, 2018 5:32 pm
Lokalizacja: Sosnowiec
Kontakt:

..to lepiej nic juz nie dotykac jesli ma byc opoiznienie:)
Awatar użytkownika
pzygmunt
Posty: 18276
Rejestracja: wt sty 19, 2016 9:26 am
Lokalizacja: Paczków
Kontakt:

Kolejna aktualizacja wrzucona na Google Drive.
Trochę poprawek i dodatkowe wykresy.
Albert
Posty: 576
Rejestracja: pt sty 04, 2019 8:32 pm
Lokalizacja: Chełm

Witajcie.

Przymierzam się do uruchomienia licznika i u siebie - kupiłem czujnik światła, wgrałem soft - teoretycznie wiem jak to odpalić, ale jest jeden problem. Wgrałem soft od @slawka z odwróconą logiką - aby liczył błyśnięcia diody. Da się zrobić w tym sofcie alby sonoff zachował normalnie swoją pierwotną funkcję czyli normalne załączanie przekaźnika? Trzeba mi go do fontanny ogrodowej + licznik energii. Z góry dziękuję za wszelaką pomoc ;)

P.S. Ten google drive to jest jakiś forumowy do wspólnego użytku?
wrobel111
Posty: 62
Rejestracja: wt cze 05, 2018 6:13 pm

pzygmunt pisze: wt kwie 30, 2019 2:49 pm Możesz dodać i 10
Pytałem o ilość bo mam licznik gazu i prądu obok siebie więc jeśli są wolne gpio w wemosie to dlaczego nie.
Postanowiłem więc stworzyć kompilację z dwoma kanałami licznika. Jednak średnio mi to idzie, pojawiają się błędy przy próbie kompilacji

Kod: Zaznacz cały

supla@supla-iotsdk:~/wrobel111/supla-espressif-esp/src$ ./build.sh impulse_counter_2_channels
make -C user clean;  make -C driver clean;  make -C supla-dev clean;
make[1]: Entering directory '/home/supla/wrobel111/supla-espressif-esp/src/user'
rm -f -r .output/eagle/debug
make[1]: Leaving directory '/home/supla/wrobel111/supla-espressif-esp/src/user'
make[1]: Entering directory '/home/supla/wrobel111/supla-espressif-esp/src/driver'
rm -f -r .output/eagle/debug
make[1]: Leaving directory '/home/supla/wrobel111/supla-espressif-esp/src/driver'
make[1]: Entering directory '/home/supla/wrobel111/supla-espressif-esp/src/supla-dev'
rm -f -r .output/eagle/debug
make[1]: Leaving directory '/home/supla/wrobel111/supla-espressif-esp/src/supla-dev'
rm -f -r .output/eagle/debug
make[1]: Entering directory '/home/supla/wrobel111/supla-espressif-esp/src/user'
DEPEND: xtensa-lx106-elf-gcc -M -Os -ggdb -std=gnu99 -Werror -Wpointer-arith -Wundef -Wall -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -D__ets__ -DICACHE_FLASH -Wno-address -g -Wpointer-arith -Wundef -Werror -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -ffunction-sections -fdata-sections -DICACHE_FLASH -DESP8266 -D__SINGLE_THREAD -D__EH_DISABLED -D__BOARD_impulse_counter_2_channels -DCFG_SECTOR=0xFC -DNOSSL=0 -D__FOTA=1 -I include -I ./ -I ../include -I ../nettle/include -I ../include -I ../include/eagle -I ../driver_lib/include supla_ds18b20.c
DEPEND: xtensa-lx106-elf-gcc -M -Os -ggdb -std=gnu99 -Werror -Wpointer-arith -Wundef -Wall -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -D__ets__ -DICACHE_FLASH -Wno-address -g -Wpointer-arith -Wundef -Werror -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -ffunction-sections -fdata-sections -DICACHE_FLASH -DESP8266 -D__SINGLE_THREAD -D__EH_DISABLED -D__BOARD_impulse_counter_2_channels -DCFG_SECTOR=0xFC -DNOSSL=0 -D__FOTA=1 -I include -I ./ -I ../include -I ../nettle/include -I ../include -I ../include/eagle -I ../driver_lib/include supla_esp_cfgmode.c
DEPEND: xtensa-lx106-elf-gcc -M -Os -ggdb -std=gnu99 -Werror -Wpointer-arith -Wundef -Wall -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -D__ets__ -DICACHE_FLASH -Wno-address -g -Wpointer-arith -Wundef -Werror -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -ffunction-sections -fdata-sections -DICACHE_FLASH -DESP8266 -D__SINGLE_THREAD -D__EH_DISABLED -D__BOARD_impulse_counter_2_channels -DCFG_SECTOR=0xFC -DNOSSL=0 -D__FOTA=1 -I include -I ./ -I ../include -I ../nettle/include -I ../include -I ../include/eagle -I ../driver_lib/include supla_esp_hw_timer.c
DEPEND: xtensa-lx106-elf-gcc -M -Os -ggdb -std=gnu99 -Werror -Wpointer-arith -Wundef -Wall -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -D__ets__ -DICACHE_FLASH -Wno-address -g -Wpointer-arith -Wundef -Werror -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -ffunction-sections -fdata-sections -DICACHE_FLASH -DESP8266 -D__SINGLE_THREAD -D__EH_DISABLED -D__BOARD_impulse_counter_2_channels -DCFG_SECTOR=0xFC -DNOSSL=0 -D__FOTA=1 -I include -I ./ -I ../include -I ../nettle/include -I ../include -I ../include/eagle -I ../driver_lib/include supla_update.c
DEPEND: xtensa-lx106-elf-gcc -M -Os -ggdb -std=gnu99 -Werror -Wpointer-arith -Wundef -Wall -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -D__ets__ -DICACHE_FLASH -Wno-address -g -Wpointer-arith -Wundef -Werror -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -ffunction-sections -fdata-sections -DICACHE_FLASH -DESP8266 -D__SINGLE_THREAD -D__EH_DISABLED -D__BOARD_impulse_counter_2_channels -DCFG_SECTOR=0xFC -DNOSSL=0 -D__FOTA=1 -I include -I ./ -I ../include -I ../nettle/include -I ../include -I ../include/eagle -I ../driver_lib/include supla_esp_cfg.c
DEPEND: xtensa-lx106-elf-gcc -M -Os -ggdb -std=gnu99 -Werror -Wpointer-arith -Wundef -Wall -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -D__ets__ -DICACHE_FLASH -Wno-address -g -Wpointer-arith -Wundef -Werror -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -ffunction-sections -fdata-sections -DICACHE_FLASH -DESP8266 -D__SINGLE_THREAD -D__EH_DISABLED -D__BOARD_impulse_counter_2_channels -DCFG_SECTOR=0xFC -DNOSSL=0 -D__FOTA=1 -I include -I ./ -I ../include -I ../nettle/include -I ../include -I ../include/eagle -I ../driver_lib/include user_main.c
DEPEND: xtensa-lx106-elf-gcc -M -Os -ggdb -std=gnu99 -Werror -Wpointer-arith -Wundef -Wall -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -D__ets__ -DICACHE_FLASH -Wno-address -g -Wpointer-arith -Wundef -Werror -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -ffunction-sections -fdata-sections -DICACHE_FLASH -DESP8266 -D__SINGLE_THREAD -D__EH_DISABLED -D__BOARD_impulse_counter_2_channels -DCFG_SECTOR=0xFC -DNOSSL=0 -D__FOTA=1 -I include -I ./ -I ../include -I ../nettle/include -I ../include -I ../include/eagle -I ../driver_lib/include supla_esp_impulse_counter.c
DEPEND: xtensa-lx106-elf-gcc -M -Os -ggdb -std=gnu99 -Werror -Wpointer-arith -Wundef -Wall -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -D__ets__ -DICACHE_FLASH -Wno-address -g -Wpointer-arith -Wundef -Werror -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -ffunction-sections -fdata-sections -DICACHE_FLASH -DESP8266 -D__SINGLE_THREAD -D__EH_DISABLED -D__BOARD_impulse_counter_2_channels -DCFG_SECTOR=0xFC -DNOSSL=0 -D__FOTA=1 -I include -I ./ -I ../include -I ../nettle/include -I ../include -I ../include/eagle -I ../driver_lib/include supla_esp_pwm.c
DEPEND: xtensa-lx106-elf-gcc -M -Os -ggdb -std=gnu99 -Werror -Wpointer-arith -Wundef -Wall -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -D__ets__ -DICACHE_FLASH -Wno-address -g -Wpointer-arith -Wundef -Werror -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -ffunction-sections -fdata-sections -DICACHE_FLASH -DESP8266 -D__SINGLE_THREAD -D__EH_DISABLED -D__BOARD_impulse_counter_2_channels -DCFG_SECTOR=0xFC -DNOSSL=0 -D__FOTA=1 -I include -I ./ -I ../include -I ../nettle/include -I ../include -I ../include/eagle -I ../driver_lib/include supla_esp_devconn.c
DEPEND: xtensa-lx106-elf-gcc -M -Os -ggdb -std=gnu99 -Werror -Wpointer-arith -Wundef -Wall -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -D__ets__ -DICACHE_FLASH -Wno-address -g -Wpointer-arith -Wundef -Werror -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -ffunction-sections -fdata-sections -DICACHE_FLASH -DESP8266 -D__SINGLE_THREAD -D__EH_DISABLED -D__BOARD_impulse_counter_2_channels -DCFG_SECTOR=0xFC -DNOSSL=0 -D__FOTA=1 -I include -I ./ -I ../include -I ../nettle/include -I ../include -I ../include/eagle -I ../driver_lib/include supla_esp_electricity_meter.c
DEPEND: xtensa-lx106-elf-gcc -M -Os -ggdb -std=gnu99 -Werror -Wpointer-arith -Wundef -Wall -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -D__ets__ -DICACHE_FLASH -Wno-address -g -Wpointer-arith -Wundef -Werror -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -ffunction-sections -fdata-sections -DICACHE_FLASH -DESP8266 -D__SINGLE_THREAD -D__EH_DISABLED -D__BOARD_impulse_counter_2_channels -DCFG_SECTOR=0xFC -DNOSSL=0 -D__FOTA=1 -I include -I ./ -I ../include -I ../nettle/include -I ../include -I ../include/eagle -I ../driver_lib/include supla_esp_gpio.c
DEPEND: xtensa-lx106-elf-gcc -M -Os -ggdb -std=gnu99 -Werror -Wpointer-arith -Wundef -Wall -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -D__ets__ -DICACHE_FLASH -Wno-address -g -Wpointer-arith -Wundef -Werror -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -ffunction-sections -fdata-sections -DICACHE_FLASH -DESP8266 -D__SINGLE_THREAD -D__EH_DISABLED -D__BOARD_impulse_counter_2_channels -DCFG_SECTOR=0xFC -DNOSSL=0 -D__FOTA=1 -I include -I ./ -I ../include -I ../nettle/include -I ../include -I ../include/eagle -I ../driver_lib/include supla_w1.c
DEPEND: xtensa-lx106-elf-gcc -M -Os -ggdb -std=gnu99 -Werror -Wpointer-arith -Wundef -Wall -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -D__ets__ -DICACHE_FLASH -Wno-address -g -Wpointer-arith -Wundef -Werror -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -ffunction-sections -fdata-sections -DICACHE_FLASH -DESP8266 -D__SINGLE_THREAD -D__EH_DISABLED -D__BOARD_impulse_counter_2_channels -DCFG_SECTOR=0xFC -DNOSSL=0 -D__FOTA=1 -I include -I ./ -I ../include -I ../nettle/include -I ../include -I ../include/eagle -I ../driver_lib/include supla_dht.c
xtensa-lx106-elf-gcc -Os -ggdb -std=gnu99 -Werror -Wpointer-arith -Wundef -Wall -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals  -D__ets__ -DICACHE_FLASH -Wno-address -g -Wpointer-arith -Wundef -Werror -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -ffunction-sections -fdata-sections  -DICACHE_FLASH -DESP8266 -D__SINGLE_THREAD -D__EH_DISABLED -D__BOARD_impulse_counter_2_channels -DCFG_SECTOR=0xFC -DNOSSL=0 -D__FOTA=1  -I include -I ./  -I ../include  -I ../nettle/include -I ../include -I ../include/eagle -I ../driver_lib/include  -o .output/eagle/debug/obj/supla_dht.o -c supla_dht.c
xtensa-lx106-elf-gcc -Os -ggdb -std=gnu99 -Werror -Wpointer-arith -Wundef -Wall -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals  -D__ets__ -DICACHE_FLASH -Wno-address -g -Wpointer-arith -Wundef -Werror -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -ffunction-sections -fdata-sections  -DICACHE_FLASH -DESP8266 -D__SINGLE_THREAD -D__EH_DISABLED -D__BOARD_impulse_counter_2_channels -DCFG_SECTOR=0xFC -DNOSSL=0 -D__FOTA=1  -I include -I ./  -I ../include  -I ../nettle/include -I ../include -I ../include/eagle -I ../driver_lib/include  -o .output/eagle/debug/obj/supla_w1.o -c supla_w1.c
xtensa-lx106-elf-gcc -Os -ggdb -std=gnu99 -Werror -Wpointer-arith -Wundef -Wall -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals  -D__ets__ -DICACHE_FLASH -Wno-address -g -Wpointer-arith -Wundef -Werror -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -ffunction-sections -fdata-sections  -DICACHE_FLASH -DESP8266 -D__SINGLE_THREAD -D__EH_DISABLED -D__BOARD_impulse_counter_2_channels -DCFG_SECTOR=0xFC -DNOSSL=0 -D__FOTA=1  -I include -I ./  -I ../include  -I ../nettle/include -I ../include -I ../include/eagle -I ../driver_lib/include  -o .output/eagle/debug/obj/supla_esp_gpio.o -c supla_esp_gpio.c
xtensa-lx106-elf-gcc -Os -ggdb -std=gnu99 -Werror -Wpointer-arith -Wundef -Wall -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals  -D__ets__ -DICACHE_FLASH -Wno-address -g -Wpointer-arith -Wundef -Werror -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -ffunction-sections -fdata-sections  -DICACHE_FLASH -DESP8266 -D__SINGLE_THREAD -D__EH_DISABLED -D__BOARD_impulse_counter_2_channels -DCFG_SECTOR=0xFC -DNOSSL=0 -D__FOTA=1  -I include -I ./  -I ../include  -I ../nettle/include -I ../include -I ../include/eagle -I ../driver_lib/include  -o .output/eagle/debug/obj/supla_esp_electricity_meter.o -c supla_esp_electricity_meter.c
xtensa-lx106-elf-gcc -Os -ggdb -std=gnu99 -Werror -Wpointer-arith -Wundef -Wall -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals  -D__ets__ -DICACHE_FLASH -Wno-address -g -Wpointer-arith -Wundef -Werror -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -ffunction-sections -fdata-sections  -DICACHE_FLASH -DESP8266 -D__SINGLE_THREAD -D__EH_DISABLED -D__BOARD_impulse_counter_2_channels -DCFG_SECTOR=0xFC -DNOSSL=0 -D__FOTA=1  -I include -I ./  -I ../include  -I ../nettle/include -I ../include -I ../include/eagle -I ../driver_lib/include  -o .output/eagle/debug/obj/supla_esp_devconn.o -c supla_esp_devconn.c
supla_esp_devconn.c: In function 'supla_esp_devconn_send_channel_values_cb':
supla_esp_devconn.c:358:3: error: implicit declaration of function 'supla_esp_board_send_channel_values_with_delay' [-Werror=implicit-function-declaration]
   supla_esp_board_send_channel_values_with_delay(devconn->srpc);
   ^
cc1: all warnings being treated as errors
/hdd2/Espressif/ESP8266_NONOS_SDK154/Makefile:322: recipe for target '.output/eagle/debug/obj/supla_esp_devconn.o' failed
make[1]: *** [.output/eagle/debug/obj/supla_esp_devconn.o] Error 1
make[1]: Leaving directory '/home/supla/wrobel111/supla-espressif-esp/src/user'
/hdd2/Espressif/ESP8266_NONOS_SDK154/Makefile:308: recipe for target '.subdirs' failed
make: *** [.subdirs] Error 2

oto przerobione przeze mnie pliki

Kod: Zaznacz cały

/*
 Copyright (C) AC SOFTWARE SP. Z O.O.

 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; either version 2
 of the License, or (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

#include <gpio.h>

typedef struct {
  char tag[3];
  _supla_int64_t counter1[4];
  _supla_int64_t counter2[4];
} _ic_storage_t;

uint8 storage_offset;

ETSTimer storage_timer1;
_supla_int64_t counter1;
_supla_int64_t counter2;
uint8 counter1_changed;
uint8 counter2_changed;
uint8 input1_last_value = 0;
uint8 input2_last_value = 0;
uint32 input1_last_time = 0;
uint32 input2_last_time = 0;

const uint8_t rsa_public_key_bytes[512] = {
    0xf2, 0xd5, 0xab, 0xa5, 0x1a, 0x6b, 0x72, 0x3b, 0xc1, 0xb1, 0x6f, 0xc0,
    0x30, 0x43, 0x6b, 0x0f, 0x01, 0x14, 0x12, 0x32, 0x38, 0x4e, 0xe4, 0x54,
    0xfe, 0x46, 0x1c, 0x97, 0xe8, 0x19, 0x9d, 0xb2, 0xd7, 0x12, 0x33, 0x18,
    0x53, 0xf1, 0x73, 0xd8, 0xfa, 0x06, 0x7a, 0xf0, 0x30, 0x44, 0x10, 0xf3,
    0x7e, 0xd9, 0x17, 0x58, 0xa0, 0x41, 0x10, 0x3e, 0x4b, 0x0b, 0x92, 0x6f,
    0x7c, 0x15, 0x6f, 0xff, 0x60, 0xc7, 0xf0, 0xb6, 0x85, 0xfc, 0xca, 0x8a,
    0xad, 0xde, 0x0b, 0xc8, 0x6b, 0x62, 0xc2, 0x2d, 0xb7, 0xce, 0xe8, 0x04,
    0x7f, 0xa8, 0x8e, 0x5e, 0x98, 0x9c, 0x5b, 0xd8, 0xa7, 0x9d, 0xa1, 0x73,
    0x2a, 0xae, 0xf4, 0x15, 0x46, 0x84, 0x54, 0x10, 0xd9, 0xec, 0x9f, 0xf5,
    0x4c, 0x09, 0xdd, 0x83, 0xdd, 0xfd, 0x65, 0x67, 0x81, 0x06, 0x3a, 0x54,
    0xc0, 0xac, 0xeb, 0xe1, 0xa5, 0xa0, 0xfa, 0x72, 0x25, 0xa4, 0x0a, 0x54,
    0x38, 0xb1, 0x70, 0x03, 0x2b, 0xda, 0x1b, 0x98, 0x6b, 0x74, 0xd6, 0x5b,
    0xef, 0x7a, 0xe0, 0xf6, 0x29, 0x04, 0x16, 0x8b, 0x05, 0xb9, 0x12, 0x8b,
    0x89, 0xf3, 0x64, 0x1b, 0xcd, 0x1e, 0x93, 0x64, 0xac, 0xdc, 0x1c, 0xcb,
    0xee, 0xad, 0x61, 0x53, 0x3e, 0x15, 0x42, 0xd4, 0x55, 0x3d, 0x41, 0x07,
    0xb2, 0xc0, 0xc0, 0x56, 0x99, 0xbc, 0xaa, 0x43, 0x78, 0xd6, 0x96, 0x41,
    0xf8, 0xa2, 0x28, 0x24, 0x29, 0xb8, 0xd9, 0x53, 0x50, 0x6a, 0x32, 0x2f,
    0x2a, 0x8f, 0x6c, 0x55, 0x1d, 0xb2, 0x10, 0x22, 0x6a, 0x6b, 0xb0, 0x5b,
    0x81, 0x92, 0xa1, 0xab, 0x6a, 0x96, 0x3f, 0x65, 0x36, 0x9a, 0x14, 0x31,
    0xf6, 0x57, 0x38, 0xd5, 0x1b, 0x2e, 0xeb, 0xe3, 0x31, 0x8c, 0xc5, 0x91,
    0x36, 0x20, 0x1c, 0x5f, 0x4f, 0x5c, 0xc5, 0xf2, 0xb5, 0x1f, 0x0d, 0xc1,
    0xa4, 0x06, 0x7c, 0x9d, 0xa8, 0x83, 0x24, 0x40, 0x9a, 0x91, 0x7a, 0x27,
    0xa6, 0xcb, 0x58, 0x59, 0xec, 0x84, 0xa1, 0x8a, 0x07, 0x34, 0x74, 0xd9,
    0x16, 0x19, 0x41, 0x17, 0x0a, 0x45, 0x05, 0x81, 0xd1, 0x33, 0xc6, 0x37,
    0xf6, 0xe1, 0x5d, 0xc9, 0x8c, 0x27, 0xcc, 0x50, 0x67, 0x9f, 0x5a, 0xda,
    0xe7, 0xab, 0x3b, 0xb8, 0x8a, 0x5d, 0x41, 0x6b, 0x79, 0x91, 0x88, 0x90,
    0xe7, 0xa3, 0x32, 0x2d, 0x20, 0xb2, 0x6f, 0xe3, 0x51, 0x43, 0x85, 0x8f,
    0x8c, 0x65, 0xc9, 0x3b, 0xda, 0xb2, 0xd7, 0x35, 0xaf, 0xd5, 0x88, 0xbc,
    0xf6, 0xde, 0x16, 0x05, 0x69, 0x22, 0xcd, 0xed, 0x07, 0x14, 0xe8, 0xd1,
    0x5d, 0x3a, 0x00, 0xd3, 0x20, 0x33, 0x6f, 0xf6, 0x25, 0xe3, 0x10, 0x0a,
    0x3b, 0x4a, 0x35, 0xbb, 0x63, 0xca, 0x65, 0xe2, 0xf4, 0xe8, 0x9d, 0x38,
    0xa1, 0x07, 0xd4, 0x87, 0x01, 0x4b, 0x5d, 0xdf, 0xc9, 0x09, 0x31, 0x9c,
    0x5a, 0xff, 0xd3, 0x83, 0xc7, 0xaf, 0x5b, 0xde, 0x95, 0x73, 0xd0, 0x6e,
    0xc7, 0x3d, 0xac, 0x3f, 0x9b, 0x2e, 0x7e, 0x92, 0x81, 0xea, 0x74, 0xbf,
    0x70, 0x04, 0x54, 0x64, 0xdf, 0x38, 0x07, 0x83, 0x86, 0xd1, 0x5b, 0x91,
    0xae, 0x72, 0x53, 0xcf, 0xd2, 0x93, 0x3b, 0x36, 0xd8, 0x75, 0x8f, 0x21,
    0xee, 0x63, 0xa4, 0xfb, 0x05, 0xc6, 0xf7, 0xbc, 0x00, 0xae, 0x10, 0x60,
    0xe3, 0x97, 0x45, 0xd6, 0x32, 0x14, 0x9f, 0xe7, 0x29, 0x70, 0x5a, 0x59,
    0x87, 0xe8, 0x3b, 0xf6, 0x0d, 0xda, 0x18, 0x5c, 0x84, 0xa0, 0x2d, 0x05,
    0x90, 0xd7, 0x79, 0xaa, 0x22, 0x2d, 0x72, 0x33, 0x0c, 0x0a, 0x13, 0xa0,
    0x00, 0xe5, 0x17, 0x74, 0xdf, 0x0c, 0xd1, 0x90, 0x15, 0x84, 0xdc, 0x34,
    0x30, 0x37, 0xae, 0xbd, 0x4b, 0xdd, 0xbc, 0x15, 0x07, 0x2c, 0x89, 0xa3,
    0xcc, 0x7f, 0x2d, 0x48, 0xf7, 0x56, 0xb9, 0x43};

void supla_esp_board_set_device_name(char *buffer, uint8 buffer_size) {
  ets_snprintf(buffer, buffer_size, "IMPULSE COUNTER 2 CHANNELS");
}

void supla_esp_board_gpio_init(void) {
  supla_input_cfg[0].type = INPUT_TYPE_BTN_MONOSTABLE;
  supla_input_cfg[0].gpio_id = B_CFG_PORT;
  supla_input_cfg[0].flags = INPUT_FLAG_PULLUP | INPUT_FLAG_CFG_BTN;

  supla_input_cfg[1].type = INPUT_TYPE_CUSTOM;
  supla_input_cfg[1].gpio_id = IMPULSE_1_PORT;
  
  supla_input_cfg[2].type = INPUT_TYPE_CUSTOM;
  supla_input_cfg[2].gpio_id = IMPULSE_2_PORT;
}

void ICACHE_FLASH_ATTR supla_esp_board_on_storage_timer(void *ptr) {
  if (counter_changed) {
    counter_changed = 0;
    storage_offset = storage_offset == 1 ? 2 : 1;

    int a;
    _ic_storage_t storage;
    storage.tag[0] = 'I';
    storage.tag[1] = 'C';
    storage.tag[2] = 1;

    _supla_int64_t c1 = counter1;
	_supla_int64_t c2 = counter2;

    for (a = 0; a < 4; a++) {
		storage.counter1[a] = c1;
    }
	
	for (a = 0; a < 4; a++) {
		storage.counter2[a] = c2;
	}

    ets_intr_lock();
    spi_flash_erase_sector(CFG_SECTOR + STATE_SECTOR_OFFSET + storage_offset);
    spi_flash_write((CFG_SECTOR + STATE_SECTOR_OFFSET + storage_offset) *
                        SPI_FLASH_SEC_SIZE,
                    (uint32 *)&storage, sizeof(_ic_storage_t));
    ets_intr_unlock();
  }
}

uint8 ICACHE_FLASH_ATTR supla_esp_board_load(uint8 offset) {
  _ic_storage_t storage;
  memset(&storage, 0, sizeof(_ic_storage_t));
  if (SPI_FLASH_RESULT_OK ==
      spi_flash_read(
          (CFG_SECTOR + STATE_SECTOR_OFFSET + offset) * SPI_FLASH_SEC_SIZE,
          (uint32 *)&storage, sizeof(_ic_storage_t))) {
    if (storage.tag[0] == 'I' && storage.tag[1] == 'C' && storage.tag[2] == 1) {
      for (int a = 1; a < 4; a++) {
        if (storage.counter1[0] != storage.counter1[a]) {
          return 0;
        }
      }

      counter1 = storage.counter1[0];
      counter1_changed = 0;
	  counter2 = storage.counter2[0];
	  counter2_changed = 0;
      return 1;
    }
  }

  return 0;
}

uint8 supla_esp_board_intr_handler(uint32 gpio_status) {
  if (gpio_status & BIT(IMPULSE_1_PORT)) {
    gpio_pin_intr_state_set(GPIO_ID_PIN(IMPULSE_1_PORT), GPIO_PIN_INTR_DISABLE);
    GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS,
                   gpio_status & BIT(IMPULSE_1_PORT));  // clear interrupt status

    uint8 v1 = gpio__input_get(IMPULSE_1_PORT);
    if (v1 != input1_last_value) {
      if (v1 == 1 && system_get_time() - input1_last_time > 50000) {
        counter1++;
        counter1_changed = 1;
      }
      input1_last_value = v1;
      input1_last_time = system_get_time();
    }
	
	uint8 v2 = gpio__input_get(IMPULSE_2_PORT);
	if (v2 != input2_last_value) {
		if (v2 == 1 && system_get_time() - input1_last_time > 50000) {
			counter2++;
			counter2_changed = 1;
		}
		input2_last_value = v2;
		input2_last_time = system_get_time();
	}

    gpio_pin_intr_state_set(GPIO_ID_PIN(IMPULSE_1_PORT), GPIO_PIN_INTR_ANYEDGE);
	gpio_pin_intr_state_set(GPIO_ID_PIN(IMPULSE_2_PORT), GPIO_PIN_INTR_ANYEDGE);

    return 1;
  }

  return 0;
}

void ICACHE_FLASH_ATTR supla_esp_board_starting(void) {
  counter1 = 0;
  counter1_changed = 0;
  counter2 = 0;
  counter2_changed = 0;
  storage_offset = 1;

  if (supla_esp_board_load(1) == 0) {
    supla_esp_board_load(2);
  }

  input1_last_value = gpio__input_get(IMPULSE_1_PORT);
  input2_last_value = gpio__input_get(IMPULSE_2_PORT);

  os_timer_disarm(&storage_timer1);
  os_timer_setfn(&storage_timer1,
                 (os_timer_func_t *)supla_esp_board_on_storage_timer, NULL);
  os_timer_arm(&storage_timer1, 1000, 1);
}

uint8 ICACHE_FLASH_ATTR supla_esp_board_get_impulse_counter(
    unsigned char channel_number, TDS_ImpulseCounter_Value *icv) {
  if (channel_number == 0) {
    icv->counter1 = counter1;
    return 1;
  }
  if (channel_number == 1) {
	  icv->counter2 = counter2;
	  return 1;
  }
  return 0;
}

void supla_esp_board_set_channels(TDS_SuplaDeviceChannel_C *channels,
                                  unsigned char *channel_count) {
  *channel_count = 2;

  channels[0].Number = 0;
  channels[0].Type = SUPLA_CHANNELTYPE_IMPULSE_COUNTER;
  supla_esp_ic_get_value(0, channels[0].value);
  
  channels[1].Number = 1;
  channels[1].Type = SUPLA_CHANNELTYPE_IMPULSE_COUNTER;
  supla_esp_ic_get_value(1, channels[1].value);
}

void supla_esp_board_send_channel_values_with_delay(void *srpc) {}

Kod: Zaznacz cały

/*
 Copyright (C) AC SOFTWARE SP. Z O.O.
 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; either version 2
 of the License, or (at your option) any later version.
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

#ifndef IMPULSE_COUNTER_2_CHANNELS_H_
#define IMPULSE_COUNTER_2_CHANNELS_H_

#define IMPULSE_COUNTER

#define IMPULSE_1_PORT 4
#define IMPULSE_2_PORT 3
#define LED_RED_PORT 5
#define B_CFG_PORT 0
#define ESP8266_SUPLA_PROTO_VERSION 10

#define BOARD_ESP_STARTING supla_esp_board_starting();
#define BOARD_INTR_HANDLER \
  if (supla_esp_board_intr_handler(gpio_status)) return

void supla_esp_board_send_channel_values_with_delay(void *srpc);
void ICACHE_FLASH_ATTR supla_esp_board_starting(void);
uint8 ICACHE_FLASH_ATTR supla_esp_board_get_impulse_counter(
    unsigned char channel_number, TDS_ImpulseCounter_Value *icv);
uint8 supla_esp_board_intr_handler(uint32 gpio_status);

#endif
Myślę, że na pewno musze jeszcze poprawić funkcję supla_esp_board_intr_handler lecz nie wiem do końca jak.

Za pomoc serdecznie dziękuję
Albert
Posty: 576
Rejestracja: pt sty 04, 2019 8:32 pm
Lokalizacja: Chełm

Witajcie
Licznik energii uruchomiony. Było to jak się okazało banalnie proste. Teraz bedzie gorzej :D gdzies mignęła mi na forum opcja taryf. Czy cos jest wiadomo jak to ustawic? Bo mam licznik z dwoma taryfami i fajnie, jakby sobie je rozdzielał.
ODPOWIEDZ

Wróć do „Zagadnienia ogólne”