Page 1 of 1

Build WIFI SOCKET x 3

Posted: Wed May 09, 2018 4:11 am
by dovico

Code: Select all

	
	#define B_RELAY1_PORT      12
	#define B_RELAY2_PORT      13
	#define B_RELAY3_PORT      14

	#define B_CFG_PORT         0
	#define B_BTN2_PORT        4
	#define B_BTN3_PORT        5

void supla_esp_board_set_device_name(char *buffer, uint8 buffer_size) {
	ets_snprintf(buffer, buffer_size, "SUPLA-SOCKETx3");
}

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[0].relay_gpio_id = B_RELAY1_PORT;
	supla_input_cfg[0].channel = 0;

	supla_input_cfg[1].type = INPUT_TYPE_BTN_MONOSTABLE;
	supla_input_cfg[1].gpio_id = B_BTN2_PORT;
	supla_input_cfg[1].flags = INPUT_FLAG_PULLUP;
	supla_input_cfg[1].relay_gpio_id = B_RELAY2_PORT;
	supla_input_cfg[1].channel = 1;

	supla_input_cfg[2].type = INPUT_TYPE_BTN_MONOSTABLE;
	supla_input_cfg[2].gpio_id = B_BTN3_PORT;
	supla_input_cfg[2].flags = INPUT_FLAG_PULLUP;
	supla_input_cfg[2].relay_gpio_id = B_RELAY3_PORT;
	supla_input_cfg[2].channel = 2;

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

    supla_relay_cfg[0].gpio_id = B_RELAY1_PORT;
    supla_relay_cfg[0].flags = RELAY_FLAG_RESET;
    supla_relay_cfg[0].channel = 0;
    
	supla_relay_cfg[1].gpio_id = B_RELAY2_PORT;
	supla_relay_cfg[1].flags = RELAY_FLAG_RESET;
	supla_relay_cfg[1].channel = 1;

	supla_relay_cfg[2].gpio_id = B_RELAY3_PORT;
	supla_relay_cfg[2].flags = RELAY_FLAG_RESET;
	supla_relay_cfg[2].channel = 2;
}

void supla_esp_board_set_channels(TDS_SuplaDeviceChannel_B *channels, unsigned char *channel_count) {
	
	*channel_count = 3;

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

	channels[0].FuncList = SUPLA_BIT_RELAYFUNC_POWERSWITCH \
								| SUPLA_BIT_RELAYFUNC_LIGHTSWITCH;

	channels[0].Default = SUPLA_CHANNELFNC_LIGHTSWITCH;

	channels[0].value[0] = supla_esp_gpio_relay_on(B_RELAY1_PORT);

	channels[1].Number = 1;
	channels[1].Type = channels[0].Type;
	channels[1].FuncList = channels[0].FuncList;
	channels[1].Default = channels[0].Default;
	channels[1].value[0] = supla_esp_gpio_relay_on(B_RELAY2_PORT);

	channels[2].Number = 2;
	channels[2].Type = channels[0].Type;
	channels[2].FuncList = channels[0].FuncList;
	channels[2].Default = channels[0].Default;
	channels[2].value[0] = supla_esp_gpio_relay_on(B_RELAY3_PORT);


}

void supla_esp_board_send_channel_values_with_delay(void *srpc) {

	supla_esp_channel_value_changed(0, supla_esp_gpio_relay_on(B_RELAY1_PORT));
	supla_esp_channel_value_changed(1, supla_esp_gpio_relay_on(B_RELAY2_PORT));
	supla_esp_channel_value_changed(2, supla_esp_gpio_relay_on(B_RELAY3_PORT));

}
When Module ESP boot or reset, B_RELAY1_PORT alway in state HIGH
I tried RELAY_FLAG_RESTORE_FORCE or RELAY_FLAG_RESTORE

i change "#define B_RELAY1_PORT 12" to "#define B_RELAY1_PORT 13" but same thing