IOT SDK

Patryk
Posts: 2944
Joined: Mon Jan 07, 2019 7:51 pm
Location: Rybnik

Post

1. Na szybko wgrałem do wemosa-a i jest możliwość ustawienia  LED ON/OFF w configu.
2. Jeszcze jedno.
Sonoff led ma na gpio13, a wemos d1 mini na gpio2
Ps.
Tak, że jak wgrywasz ten soft do wemosa-a dioda led nie będzie działać.
You do not have the required permissions to view the files attached to this post.
bicker
Posts: 483
Joined: Tue Feb 02, 2016 8:18 am

Post

właśnie sprawdizłem jeszcze raz i jest ok.
z tymi pinami to nawwet nie sprawdzałem i może dlatego, ale dzięki
czyli muszę sobie przejrzec inne płytki aby zweryfikować piny ...

dzięki za cierpliwość :)

pewnie jeszcze będę pytał

z LED ON/OFF już mam płytkę ogarniętą, i wiem co zmienić dla następnej. .... :)
wygenerowany plik 2.
z filtrem od - djack2017
Timer
LED ON/OFF
i flagą stanu
sonoff_led.7z
oczywiście dla sonoffa basic


teraz mono / bistabilny
ale to widzę, że będzie wiecej pisania....
You do not have the required permissions to view the files attached to this post.
Last edited by bicker on Fri Sep 11, 2020 6:55 am, edited 2 times in total.
Patryk
Posts: 2944
Joined: Mon Jan 07, 2019 7:51 pm
Location: Rybnik

Post

bicker wrote: Fri Sep 11, 2020 6:02 am
teraz mono / bistabilny
ale to widzę, że będzie wiecej pisania....
Przejrzyj sobie inCan-a.
Tam to jest.
Edit:
https://github.com/SUPLA/supla-espressi ... Can.c#L319

 https://github.com/SUPLA/supla-espressi ... nCan.c#L65
bicker
Posts: 483
Joined: Tue Feb 02, 2016 8:18 am

Post

Witam walczę z przełącznikiem mono/bistabilnym

wzorując się na inCan, mój kod wygląda tak...

Code: Select all

/*
 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.
 */



#define B_RELAY1_PORT    12
#define B_CFG_PORT        0

void ICACHE_FLASH_ATTR supla_esp_board_set_device_name(char *buffer, uint8 buffer_size) {
	
		ets_snprintf(buffer, buffer_size, "Sonoff led timer_test");
}
char *ICACHE_FLASH_ATTR supla_esp_board_cfg_html_template(
    char dev_name[25], const char mac[6], const char data_saved) {
  static char html_template_header[] =
      "<!DOCTYPE html><meta http-equiv=\"content-type\" content=\"text/html; "
      "charset=UTF-8\"><meta name=\"viewport\" "
      "content=\"width=device-width,initial-scale=1,maximum-scale=1,user-"
      "scalable=no\"><style>body{font-size:14px;font-family:HelveticaNeue,"
      "\"Helvetica Neue\",HelveticaNeueRoman,HelveticaNeue-Roman,\"Helvetica "
      "Neue "
      "Roman\",TeXGyreHerosRegular,Helvetica,Tahoma,Geneva,Arial,sans-serif;"
      "font-weight:400;font-stretch:normal;background:#00d151;color:#fff;line-"
      "height:20px;padding:0}.s{width:460px;margin:0 auto;margin-top:calc(50vh "
      "- 340px);border:solid 3px #fff;padding:0 10px "
      "10px;border-radius:3px}#l{display:block;max-width:150px;height:155px;"
      "margin:-80px auto 20px;background:#00d151;padding-right:5px}#l "
      "path{fill:#000}.w{margin:3px 0 16px;padding:5px "
      "0;border-radius:3px;background:#fff;box-shadow:0 1px 3px "
      "rgba(0,0,0,.3)}h1,h3{margin:10px "
      "8px;font-family:HelveticaNeueLight,HelveticaNeue-Light,\"Helvetica Neue "
      "Light\",HelveticaNeue,\"Helvetica "
      "Neue\",TeXGyreHerosRegular,Helvetica,Tahoma,Geneva,Arial,sans-serif;"
      "font-weight:300;font-stretch:normal;color:#000;font-size:23px}h1{margin-"
      "bottom:14px;color:#fff}span{display:block;margin:10px 7px "
      "14px}i{display:block;font-style:normal;position:relative;border-bottom:"
      "solid 1px "
      "#00d151;height:42px}i:last-child{border:none}label{position:absolute;"
      "display:inline-block;top:0;left:8px;color:#00d151;line-height:41px;"
      "pointer-events:none}input,select{width:calc(100% - "
      "145px);border:none;font-size:16px;line-height:40px;border-radius:0;"
      "letter-spacing:-.5px;background:#fff;color:#000;padding-left:144px;-"
      "webkit-appearance:none;-moz-appearance:none;appearance:none;outline:0!"
      "important;height:40px}select{padding:0;float:right;margin:1px 3px 1px "
      "2px}button{width:100%;border:0;background:#000;padding:5px "
      "10px;font-size:16px;line-height:40px;color:#fff;border-radius:3px;box-"
      "shadow:0 1px 3px "
      "rgba(0,0,0,.3);cursor:pointer}.c{background:#ffe836;position:fixed;"
      "width:100%;line-height:80px;color:#000;top:0;left:0;box-shadow:0 1px "
      "3px rgba(0,0,0,.3);text-align:center;font-size:26px;z-index:100}@media "
      "all and (max-height:920px){.s{margin-top:80px}}@media all and "
      "(max-width:900px){.s{width:calc(100% - "
      "20px);margin-top:40px;border:none;padding:0 "
      "8px;border-radius:0}#l{max-width:80px;height:auto;margin:10px auto "
      "20px}h1,h3{font-size:19px}i{border:none;height:auto}label{display:block;"
      "margin:4px 0 "
      "12px;color:#00d151;font-size:13px;position:relative;line-height:18px}"
      "input,select{width:calc(100% - "
      "10px);font-size:16px;line-height:28px;padding:0 5px;border-bottom:solid "
      "1px #00d151}select{width:100%;float:none;margin:0}}</style><script "
      "type=\"text/javascript\">setTimeout(function(){var element =  "
      "document.getElementById('msg');if ( element != null ) "
      "element.style.visibility = \"hidden\";},3200);</script>";
  static char html_template[] =
      "%s%s<div class=\"s\"><svg version=\"1.1\" id=\"l\" x=\"0\" y=\"0\" "
      "viewBox=\"0 0 200 200\" xml:space=\"preserve\"><path "
      "d=\"M59.3,2.5c18.1,0.6,31.8,8,40.2,23.5c3.1,5.7,4.3,11.9,4.1,18.3c-0.1,"
      "3.6-0.7,7.1-1.9,10.6c-0.2,0.7-0.1,1.1,0.6,1.5c12.8,7.7,25.5,15.4,38.3,"
      "23c2.9,1.7,5.8,3.4,8.7,5.3c1,0.6,1.6,0.6,2.5-0.1c4.5-3.6,9.8-5.3,15.7-5."
      "4c12.5-0.1,22.9,7.9,25.2,19c1.9,9.2-2.9,19.2-11.8,23.9c-8.4,4.5-16.9,4."
      "5-25.5,0.2c-0.7-0.3-1-0.2-1.5,0.3c-4.8,4.9-9.7,9.8-14.5,14.6c-5.3,5.3-"
      "10.6,10.7-15.9,16c-1.8,1.8-3.6,3.7-5.4,5.4c-0.7,0.6-0.6,1,0,1.6c3.6,3.4,"
      "5.8,7.5,6.2,12.2c0.7,7.7-2.2,14-8.8,18.5c-12.3,8.6-30.3,3.5-35-10.4c-2."
      "8-8.4,0.6-17.7,8.6-22.8c0.9-0.6,1.1-1,0.8-2c-2-6.2-4.4-12.4-6.6-18.6c-6."
      "3-17.6-12.7-35.1-19-52.7c-0.2-0.7-0.5-1-1.4-0.9c-12.5,0.7-23.6-2.6-33-"
      "10.4c-8-6.6-12.9-15-14.2-25c-1.5-11.5,1.7-21.9,9.6-30.7C32.5,8.9,42.2,4."
      "2,53.7,2.7c0.7-0.1,1.5-0.2,2.2-0.2C57,2.4,58.2,2.5,59.3,2.5z "
      "M76.5,81c0,0.1,0.1,0.3,0.1,0.6c1.6,6.3,3.2,12.6,4.7,18.9c4.5,17.7,8.9,"
      "35.5,13.3,53.2c0.2,0.9,0.6,1.1,1.6,0.9c5.4-1.2,10.7-0.8,15.7,1.6c0.8,0."
      "4,1.2,0.3,1.7-0.4c11.2-12.9,22.5-25.7,33.4-38.7c0.5-0.6,0.4-1,0-1.6c-5."
      "6-7.9-6.1-16.1-1.3-24.5c0.5-0.8,0.3-1.1-0.5-1.6c-9.1-4.7-18.1-9.3-27.2-"
      "14c-6.8-3.5-13.5-7-20.3-10.5c-0.7-0.4-1.1-0.3-1.6,0.4c-1.3,1.8-2.7,3.5-"
      "4.3,5.1c-4.2,4.2-9.1,7.4-14.7,9.7C76.9,80.3,76.4,80.3,76.5,81z "
      "M89,42.6c0.1-2.5-0.4-5.4-1.5-8.1C83,23.1,74.2,16.9,61.7,15.8c-10-0.9-18."
      "6,2.4-25.3,9.7c-8.4,9-9.3,22.4-2.2,32.4c6.8,9.6,19.1,14.2,31.4,11.9C79."
      "2,67.1,89,55.9,89,42.6z "
      "M102.1,188.6c0.6,0.1,1.5-0.1,2.4-0.2c9.5-1.4,15.3-10.9,11.6-19.2c-2.6-5."
      "9-9.4-9.6-16.8-8.6c-8.3,1.2-14.1,8.9-12.4,16.6C88.2,183.9,94.4,188.6,"
      "102.1,188.6z "
      "M167.7,88.5c-1,0-2.1,0.1-3.1,0.3c-9,1.7-14.2,10.6-10.8,18.6c2.9,6.8,11."
      "4,10.3,19,7.8c7.1-2.3,11.1-9.1,9.6-15.9C180.9,93,174.8,88.5,167.7,88."
      "5z\"/></svg><h1>%s</h1><span>LAST STATE: %s<br>Firmware: %s<br>GUID: "
      "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X<br>MAC:"
      " %02X:%02X:%02X:%02X:%02X:%02X</span><form method=\"post\"><div "
      "class=\"w\"><h3>Wi-Fi Settings</h3><i><input name=\"sid\" "
      "value=\"%s\"><label>Network name</label></i><i><input "
      "name=\"wpw\"><label>Password</label></i></div><div "
      "class=\"w\"><h3>Supla Settings</h3><i><input name=\"svr\" "
      "value=\"%s\"><label>Server</label></i><i><input name=\"eml\" "
      "value=\"%s\"><label>E-mail</label></i></div><div "
      "class=\"w\"><h3>Additional Settings</h3><i><select name=\"led\"><option "
      "value=\"0\" %s>LED "
      "ON<option value=\"1\" %s>LED OFF</select><label>Status - "
      "connected</label></i>" 
	  "<i><select name=\"bt1\"><option value=\"0\" %s>Monostable<option "         	//menu bi/mono
      "value=\"1\" %s>Bistable</select><label>Button1 type:</label></i>"				//menu bi/mono
	  "</div><button type=\"submit\">SAVE</button></form></div><br><br>";		//menu bi/mono

  int bufflen = strlen(supla_esp_devconn_laststate()) + strlen(dev_name) +
                strlen(SUPLA_ESP_SOFTVER) + strlen(supla_esp_cfg.WIFI_SSID) +
                strlen(supla_esp_cfg.Server) + strlen(supla_esp_cfg.Email) +
                strlen(html_template_header) + strlen(html_template) + 200;

  char *buffer = (char *)malloc(bufflen);

  ets_snprintf(
      buffer, bufflen, html_template, html_template_header,
      data_saved == 1 ? "<div id=\"msg\" class=\"c\">Data saved</div>" : "",
      dev_name, supla_esp_devconn_laststate(), SUPLA_ESP_SOFTVER,
      (unsigned char)supla_esp_cfg.GUID[0],
      (unsigned char)supla_esp_cfg.GUID[1],
      (unsigned char)supla_esp_cfg.GUID[2],
      (unsigned char)supla_esp_cfg.GUID[3],
      (unsigned char)supla_esp_cfg.GUID[4],
      (unsigned char)supla_esp_cfg.GUID[5],
      (unsigned char)supla_esp_cfg.GUID[6],
      (unsigned char)supla_esp_cfg.GUID[7],
      (unsigned char)supla_esp_cfg.GUID[8],
      (unsigned char)supla_esp_cfg.GUID[9],
      (unsigned char)supla_esp_cfg.GUID[10],
      (unsigned char)supla_esp_cfg.GUID[11],
      (unsigned char)supla_esp_cfg.GUID[12],
      (unsigned char)supla_esp_cfg.GUID[13],
      (unsigned char)supla_esp_cfg.GUID[14],
      (unsigned char)supla_esp_cfg.GUID[15], (unsigned char)mac[0],
      (unsigned char)mac[1], (unsigned char)mac[2], (unsigned char)mac[3],
      (unsigned char)mac[4], (unsigned char)mac[5], supla_esp_cfg.WIFI_SSID,
      supla_esp_cfg.Server, supla_esp_cfg.Email,
      supla_esp_cfg.StatusLedOff == 0 ? "selected" : "",
      supla_esp_cfg.StatusLedOff == 1 ? "selected" : "",
      supla_esp_cfg.Button1Type == BTN_TYPE_MONOSTABLE ? "selected" : "",		//menu bi/mono
      supla_esp_cfg.Button1Type == BTN_TYPE_BISTABLE ? "selected" : ""			//menu bi/mono
	);
 return buffer;
 }

void ICACHE_FLASH_ATTR supla_esp_board_gpio_init(void) {

	supla_input_cfg[0].type = supla_esp_cfg.Button1Type == BTN_TYPE_BISTABLE         //menu bi/mono
		? INPUT_TYPE_BTN_TYPE_BISTABLE																//menu bi/mono
		? INPUT_TYPE_BTN_TYPE_MONOSTABLE															//menu bi/mono
	supla_input_cfg[0].gpio_id = B_CFG_PORT;
	supla_input_cfg[0].flags = INPUT_FLAG_PULLUP | INPUT_FLAG_CFG_BTN;
	supla_input_cfg[0].relay_gpio_id = B_RELAY1_PORT;
	supla_input_cfg[0].channel = 0;

	// ---------------------------------------
	// ---------------------------------------

    supla_relay_cfg[0].gpio_id = B_RELAY1_PORT;
    supla_relay_cfg[0].flags = RELAY_FLAG_RESTORE_FORCE;
    supla_relay_cfg[0].channel = 0;
   
}

void ICACHE_FLASH_ATTR supla_esp_board_set_channels(TDS_SuplaDeviceChannel_C *channels, unsigned char *channel_count) {

	*channel_count = 1;

	channels[0].Number = 0;
	channels[0].Type = SUPLA_CHANNELTYPE_RELAY;

	channels[0].FuncList = SUPLA_BIT_FUNC_POWERSWITCH \
								| SUPLA_BIT_FUNC_LIGHTSWITCH;

	channels[0].Default = SUPLA_CHANNELFNC_POWERSWITCH;
    channels[0].Flags |= SUPLA_CHANNEL_FLAG_COUNTDOWN_TIMER_SUPPORTED;   //Timer
  
	channels[0].Flags |= SUPLA_CHANNEL_FLAG_CHANNELSTATE; // Nowy poziom wifi itd...
	
     channels[0].value[0] = supla_esp_gpio_relay_on(B_RELAY1_PORT);
	 }

void ICACHE_FLASH_ATTR supla_esp_board_on_connect(void) {
  supla_esp_gpio_set_led(supla_esp_cfg.StatusLedOff, 0, 0);
}

void ICACHE_FLASH_ATTR
supla_esp_board_send_channel_values_with_delay(void *srpc) {

	supla_esp_channel_value_changed(0, supla_esp_gpio_relay_on(B_RELAY1_PORT));

}
podczas kompilacji mam takie błędy

Code: Select all

../include/board/sonoff_led.c: In function 'supla_esp_board_gpio_init':
../include/board/sonoff_led.c:162:5: error: 'INPUT_TYPE_BTN_TYPE_BISTABLE' undeclared (first use in this function)
   ? INPUT_TYPE_BTN_TYPE_BISTABLE                //menu bi/mono
     ^
../include/board/sonoff_led.c:162:5: note: each undeclared identifier is reported only once for each function it appears in
../include/board/sonoff_led.c:163:5: error: 'INPUT_TYPE_BTN_TYPE_MONOSTABLE' undeclared (first use in this function)
   ? INPUT_TYPE_BTN_TYPE_MONOSTABLE               //menu bi/mono
     ^
../include/board/sonoff_led.c:164:2: error: expected ':' before 'supla_input_cfg'
  supla_input_cfg[0].gpio_id = B_CFG_PORT;
  ^
/hdd2/Espressif/ESP8266_NONOS_SDK154/Makefile:322: recipe for target '.output/eagle/debug/obj/user_main.o' failed
make[1]: *** [.output/eagle/debug/obj/user_main.o] Error 1
make[1]: Leaving directory '/CProjects/supla-espressif-esp/src/user'
/hdd2/Espressif/ESP8266_NONOS_SDK154/Makefile:308: recipe for target '.subdirs' failed
make: *** [.subdirs] Error 2
domyślam się, że brakuje mi obsługi przycisku jako bistabilny, czy monostabilny
ale nie wiem jak sobie z tym poradzić...

czy któś mógłby pomóc. ?
User avatar
kris.sg
Posts: 482
Joined: Mon Aug 07, 2017 8:08 pm
Location: Przezchlebie
Has thanked: 1 time
Been thanked: 1 time

Post

masz błąd tutaj :

Code: Select all

supla_input_cfg[0].type = supla_esp_cfg.Button1Type == BTN_TYPE_BISTABLE         //menu bi/mono
		? INPUT_TYPE_BTN_TYPE_BISTABLE																//menu bi/mono
		? INPUT_TYPE_BTN_TYPE_MONOSTABLE		
tu masz jak to powinno wyglądać :

Code: Select all

   supla_input_cfg[0].type = supla_esp_cfg.Button1Type == BTN_TYPE_BISTABLE
        ? INPUT_TYPE_BTN_BISTABLE
        : INPUT_TYPE_BTN_MONOSTABLE;
■Rpi4(m.2) Supla Cloud, Scripts ■Rpi3(sd) SD: 6x MI ATC, 1x W.S.
ROLETY_V3 x12 ■SWITCH_DUAL x4 ■GATE_MODULE_V3 x1 ■SOCKET_SSR x1 ■SMOKE_MODULE x1
SONOFF_TOUCH x4 ■YUNSCHAN x1 ■STAITCASE_DIMMER x1 ■MEW-01 x2 ■mROW-02 x1 ■LEW-01 x1
POW_R2 x2 ■SP111 x3
bicker
Posts: 483
Joined: Tue Feb 02, 2016 8:18 am

Post

dzięki wielki
już poprawione
bicker
Posts: 483
Joined: Tue Feb 02, 2016 8:18 am

Post

a teraz tak...
chciałbym aby w sonofie
standardowo działał gpio0 jako monostabilny

a gpio14 miałbym wybór na stronie konfiguracyjnej.

czy nie ma ograniczenia, że 2 przyciski sterują jendym przekaznikiem ?
czy nie będzie konfliktu ?
User avatar
kris.sg
Posts: 482
Joined: Mon Aug 07, 2017 8:08 pm
Location: Przezchlebie
Has thanked: 1 time
Been thanked: 1 time

Post

Męczę się jakiś czas z kodem, chcę poprzez zmianę stanu kanału (w aplikacji ) wywołać restart modułu:
w plytce c:

Code: Select all

void supla_esp_board_gpiooutput_set_hi(uint8 port, uint8 hi) {

	if ( hi == 1 ) {
	
		supla_log(LOG_DEBUG, "update, port = %i", port);
		
		if ( supla_esp_cfg.FirmwareUpdate == 1 ) {
			
			supla_esp_state.Relay[1] = 1;;
			supla_esp_save_state(SAVE_STATE_DELAY);
			supla_esp_channel_value_changed(1, 1);
			supla_log(LOG_DEBUG, "update restart ");
			supla_system_restart();
		};
		
		if ( supla_esp_cfg.FirmwareUpdate == 0 ) {
			supla_esp_cfg.FirmwareUpdate = 1; 
			supla_esp_cfg_save(&supla_esp_cfg);
		};
		
	};
w plytce h mam:

Code: Select all

#define BOARD_GPIO_OUTPUT_SET_HI if ( port >= 20 ) { supla_esp_board_gpiooutput_set_hi(port, hi); return; };

void supla_esp_board_gpiooutput_set_hi(uint8 port, uint8 hi);
Po zmianie stanu w aplikacji kod ma wysłać zmianę stanu do clouda i wykonać restart.
I tu jest problem bo zmiana stanu następuje po zakończeniu wykonania kodu w "supla_esp_board_gpiooutput_set_hi",
czyli restart przerywa wykonanie kodu i nie wysyła zmiany stanu,
jak zakomentuję "supla_system_restart();" wtedy kod się wykona i stan w aplikacji się zmienia.
Da się to jakoś ugryźć ?
■Rpi4(m.2) Supla Cloud, Scripts ■Rpi3(sd) SD: 6x MI ATC, 1x W.S.
ROLETY_V3 x12 ■SWITCH_DUAL x4 ■GATE_MODULE_V3 x1 ■SOCKET_SSR x1 ■SMOKE_MODULE x1
SONOFF_TOUCH x4 ■YUNSCHAN x1 ■STAITCASE_DIMMER x1 ■MEW-01 x2 ■mROW-02 x1 ■LEW-01 x1
POW_R2 x2 ■SP111 x3
deolsunny533
Posts: 1
Joined: Thu Oct 22, 2020 3:01 pm

Post

A w tym lapku masz procesor z instrukcjami x64 więc śmiało możesz instalować taką wersje Ubuntu.
and
bicker
Posts: 483
Joined: Tue Feb 02, 2016 8:18 am

Post

Witam,
chciałbym na sonoffie zrobić aby na

GPIO14 był przycisk
GPIO1 DS
GPIO3 DHT

czy będzie to działać
wiem, że 1 i 3 to TX i RX

Return to “Zagadnienia ogólne”