Exemplo n.º 1
0
void
setup_server ( void )
{
    register struct espconn *c = &server_conn;
    char *x;

    c->type = ESPCONN_TCP;
    c->state = ESPCONN_NONE;
    my_tcp_conn.local_port=88;
    c->proto.tcp=&my_tcp_conn;

    espconn_regist_reconcb ( c, tcp_reconnect_cb);
    espconn_regist_connectcb ( c, tcp_connect_cb);
    espconn_regist_disconcb ( c, tcp_disconnect_cb);

    if ( espconn_accept(c) != ESPCONN_OK ) {
	os_printf("Error starting server %d\n", 0);
	return;
    }

    /* Interval in seconds to timeout inactive connections */
    espconn_regist_time(c, 20, 0);

    // x = (char *) os_zalloc ( 4 );
    // os_printf ( "Got mem: %08x\n", x );

    os_printf ( "Server ready\n" );
}
Exemplo n.º 2
0
void user_init()
{
#ifdef ESP8266_GDBSTUB
	gdbstub_init();
#endif

	//Uncomment the line below if you want to step through the initialization function in the debugger without getting a reset from a watchdog.
	//system_soft_wdt_stop();
	struct ip_info info;
	struct softap_config cfg;
	wifi_softap_get_config(&cfg);
	strcpy((char *)cfg.ssid, "$$com.sysprogs.esp8266.http.ssid$$");
	cfg.ssid_len = strlen((char*)cfg.ssid);
	wifi_softap_set_config_current(&cfg);
	wifi_set_opmode(SOFTAP_MODE);
	
	wifi_softap_dhcps_stop();
	IP4_ADDR(&info.ip, 192, 168, $$com.sysprogs.esp8266.http.subnet$$, 1);
	IP4_ADDR(&info.gw, 192, 168, $$com.sysprogs.esp8266.http.subnet$$, 1);
	IP4_ADDR(&info.netmask, 255, 255, 255, 0);
	wifi_set_ip_info(SOFTAP_IF, &info);
	dhcps_lease_test();
	wifi_softap_dhcps_start();
	
	static struct espconn httpdConn;
	static esp_tcp httpdTcp;
	httpdConn.type = ESPCONN_TCP;
	httpdConn.state = ESPCONN_NONE;
	httpdTcp.local_port = 80;
	httpdConn.proto.tcp = &httpdTcp;

	espconn_regist_connectcb(&httpdConn, httpdConnectCb);
	espconn_accept(&httpdConn);
}
Exemplo n.º 3
0
void user_init(void)
{
	//gpio_init();
	uart_init(BIT_RATE_115200, BIT_RATE_115200);
	int at_wifiMode = wifi_get_opmode();

	uart0_sendStr("\r\nCustom Server\r\n");

	wifi_set_opmode( 2 ); //We broadcast our ESSID, wait for peopel to join.

	pTcpServer = (struct espconn *)os_zalloc(sizeof(struct espconn));
	pTcpServer->type = ESPCONN_TCP;
	pTcpServer->state = ESPCONN_NONE;
	pTcpServer->proto.tcp = (esp_tcp *)os_zalloc(sizeof(esp_tcp));
	pTcpServer->proto.tcp->local_port = PORT;
	espconn_regist_connectcb(pTcpServer, at_tcpserver_listen);
	espconn_accept(pTcpServer);
	espconn_regist_time(pTcpServer, SERVER_TIMEOUT, 0);

	printf("Hello, world.  Starting server.\n" );
	InitDumbcraft();
	
	os_sprintf( my_server_name, "ESP8266Dumb" );

	system_os_task(at_procTask, at_procTaskPrio, at_procTaskQueue, at_procTaskQueueLen);

	uart0_sendStr("\r\nCustom Server\r\n");
	system_os_post(at_procTaskPrio, 0, 0 );
}
Exemplo n.º 4
0
void TcpServer::listen() {
LOGF(" Listen on port : %d ", _local_port);
if (espconn_accept(_conn) != ESPCONN_OK) {
	LOGF("ERR : espconn_accept");
}
espconn_regist_connectcb(_conn, connectCb);
}
Exemplo n.º 5
0
void user_init(void)
{
	uart_init(BIT_RATE_115200, BIT_RATE_115200);
	int at_wifiMode = wifi_get_opmode();

	uart0_sendStr("\r\nCustom Server\r\n");

	wifi_set_opmode( 2 ); //We broadcast our ESSID, wait for peopel to join.

    pUdpServer = (struct espconn *)os_zalloc(sizeof(struct espconn));
    if (pUdpServer == NULL)
    {
      uart0_sendStr("UdpServer Failure\r\n");
      return;
    }
    pUdpServer->type = ESPCONN_UDP;
    pUdpServer->state = ESPCONN_NONE;
    pUdpServer->proto.udp = (esp_udp *)os_zalloc(sizeof(esp_udp));
    pUdpServer->proto.udp->local_port = PORT;
    pUdpServer->reverse = NULL;
    espconn_regist_recvcb(pUdpServer, at_udpserver_recv);
    espconn_accept(pUdpServer);


	char outbuffer[] = { 0xff, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff };
	WS2812OutBuffer( outbuffer, sizeof(outbuffer) );

	system_os_task(at_procTask, at_procTaskPrio, at_procTaskQueue, at_procTaskQueueLen);

	uart0_sendStr("\r\nCustom Server\r\n");
	system_os_post(at_procTaskPrio, 0, 0 );
}
Exemplo n.º 6
0
void ICACHE_FLASH_ATTR
tcpserver_init(void)
{
    int8_t res;

    tcp_server.type = ESPCONN_TCP;
    tcp_server.state = ESPCONN_NONE;
    tcp_server.proto.tcp = &tcp_config;
    tcp_server.proto.tcp->local_port = TCP_SERVER_LOCAL_PORT;

    espconn_regist_connectcb(&tcp_server, incoming_connection_callback);

    espconn_tcp_set_max_con_allow(&tcp_server, 1); //Allow 1 connection max

    res = espconn_accept(&tcp_server);

    if(res == 0)
        os_printf("Created TCP server on port %d, running on ROM %d, AP RSSI: %ddBm, WiFi mode: %d.\r\n", 
                tcp_server.proto.tcp->local_port,
                system_upgrade_userbin_check(),
                wifi_station_get_rssi(),
                wifi_get_phy_mode());
    else
        os_printf("Failed to create TCP server, error code: %d.\r\n", res);
}
Exemplo n.º 7
0
void ICACHE_FLASH_ATTR http_ws_server_start(){


	NODE_DBG("Websocket server start, conn=%p", &ws_config.server_conn);
	espconn_regist_connectcb(&ws_config.server_conn, http_ws_connect_callback);	
	espconn_accept(&ws_config.server_conn);

}
Exemplo n.º 8
0
void start_http_eval_server() {
  printf("\nStarting HTTP eval server\n");
  server.type = ESPCONN_TCP;
  server.proto.tcp = &server_tcp;
  server_tcp.local_port = 80;

  espconn_regist_connectcb(&server, server_connect_cb);
  espconn_accept(&server);
}
Exemplo n.º 9
0
void ICACHE_FLASH_ATTR serverConnect(void) {
    sint8 res;
    res = espconn_regist_connectcb(serverConn, serverConnectCb);
    DBG_MSG("espconn_regist_connectcb, res: %d\r\n", res);
    res = espconn_accept(serverConn);
    DBG_MSG("espconn_accept, res: %d\r\n", res);
    res = espconn_regist_time(serverConn, SERVER_TIMEOUT, 0);
    DBG_MSG("espconn_regist_time, res: %d\r\n", res);
}
Exemplo n.º 10
0
void ICACHE_FLASH_ATTR setup_server() {
    server.type = ESPCONN_TCP;
    server.state = ESPCONN_NONE;
    server.proto.tcp = (esp_tcp *)os_zalloc(sizeof(esp_tcp));
    server.proto.tcp->local_port = 80;
    espconn_regist_connectcb(&server, tcpserver_connectcb);
    espconn_accept(&server);
    espconn_regist_time(&server, server_timeover, 0);
}
Exemplo n.º 11
0
//Initialize listening socket, do general initialization
void ICACHE_FLASH_ATTR httpdPlatInit(int port, int maxConnCt) {
	httpdConn.type=ESPCONN_TCP;
	httpdConn.state=ESPCONN_NONE;
	httpdTcp.local_port=port;
	httpdConn.proto.tcp=&httpdTcp;
	espconn_regist_connectcb(&httpdConn, platConnCb);
	espconn_accept(&httpdConn);
	espconn_regist_time(&httpdConn, HTTPD_CONN_TIMEOUT, 0); // Configure timeout
	espconn_tcp_set_max_con_allow(&httpdConn, (uint8) maxConnCt);
}
Exemplo n.º 12
0
void start_data_gen_server(int port) {
  struct espconn *server = (struct espconn *) calloc(1, sizeof(*server));
  esp_tcp *tcp = (esp_tcp *) calloc(1, sizeof(*tcp));

  server->type = ESPCONN_TCP;
  server->proto.tcp = tcp;
  tcp->local_port = port;

  espconn_regist_connectcb(server, echo_connect_cb);
  espconn_accept(server);
}
Exemplo n.º 13
0
LOCAL void ICACHE_FLASH_ATTR setupTCP() {
    conn1.type = ESPCONN_TCP;
    conn1.state = ESPCONN_NONE;
    tcp1.local_port = 8080;
    conn1.proto.tcp = &tcp1;
    espconn_accept(&conn1); 
    espconn_create(&conn1);
    espconn_regist_connectcb(&conn1, recvCB); 
    
    //espconn_regist_recvcb(&conn1, recvCB);
    os_printf("Listening for data\n");
} // End of setupUDP
Exemplo n.º 14
0
void ICACHE_FLASH_ATTR
user_tcpserver_init(uint32 port)
{
    esp_conn.type = ESPCONN_TCP;
    esp_conn.state = ESPCONN_NONE;
    esp_conn.proto.tcp = &esptcp;
    esp_conn.proto.tcp->local_port = port;
    espconn_regist_connectcb(&esp_conn, tcpserver_listen);

    sint8 ret = espconn_accept(&esp_conn);
    
    os_printf("ESP listen to incoming tcp connections [%d]!\r\n", ret);
}
Exemplo n.º 15
0
/**
  @brief Accept an incomming connection, setup connect_callback
  @param[in] *esp_config, ESP8266 network type an mode configuration structure
  @param[in] *esp_tcp_config,  network protocol structure
  @param[in] port,  network port to listen on
  @param[in] connect_callback: connection callback function pointer
  @return void
*/
MEMSPACE
static void tcp_accept(struct espconn *esp_config, esp_tcp *esp_tcp_config,
		uint16_t port, void (*connect_callback)(struct espconn *))
{
	memset(esp_tcp_config, 0, sizeof(*esp_tcp_config));
	esp_tcp_config->local_port = port;
	memset(esp_config, 0, sizeof(*esp_config));
	esp_config->type = ESPCONN_TCP;
	esp_config->state = ESPCONN_NONE;
	esp_config->proto.tcp = esp_tcp_config;
	espconn_regist_connectcb(esp_config, (espconn_connect_callback)connect_callback);
	espconn_accept(esp_config);
	espconn_tcp_set_max_con_allow(esp_config, 1);
}
void ICACHE_FLASH_ATTR dhap_httpd_init() {
	struct espconn *httpdConn = (struct espconn *)os_zalloc(sizeof(struct espconn ));
	esp_tcp *httpdTcp = (esp_tcp *)os_zalloc(sizeof(esp_tcp));
	httpdConn->type = ESPCONN_TCP;
	httpdConn->state = ESPCONN_NONE;
	httpdTcp->local_port = HTTPD_PORT;
	httpdConn->proto.tcp = httpdTcp;

	espconn_regist_connectcb(httpdConn, dhap_httpd_connect_cb);
	espconn_regist_reconcb(httpdConn, dhap_httpd_reconnect_cb);
	sint8 res = espconn_accept(httpdConn);
	if(res)
		dhdebug("espconn_accept returned: %d", res);
}
Exemplo n.º 17
0
void
esp8266_tcp_stream_bind(lws_sockfd_type fd, int port, struct lws *wsi)
{
	fd->proto.tcp->local_port = port;
	fd->reverse = wsi;

	hacky_context = wsi->context;

	espconn_regist_connectcb(fd, esp8266_cb_connect);
	/* hmmm it means, listen() + accept() */
	espconn_accept(fd);

	espconn_tcp_set_max_con_allow(fd, 10);
}
Exemplo n.º 18
0
static int   do_listen(int argc, const char* argv[])
{
	int port = skip_atoi(&argv[1]);
	console_printf("Listening (TCP) on port %d\n", port);
	esp_conn.type = ESPCONN_TCP;
	esp_conn.state = ESPCONN_NONE;
	esp_conn.proto.tcp = &esptcp;
	esp_conn.proto.tcp->local_port = port;
	espconn_regist_connectcb(&esp_conn, webserver_listen);
	espconn_accept(&esp_conn);
	linebuffer = os_malloc(LINEBUFFER_SIZE);
	lineptr = 0;
	console_lock(1);
}
Exemplo n.º 19
0
void ICACHE_FLASH_ATTR websocketdInit(int port, WSOnConnection onConnection) {

	wsOnConnectionCallback = onConnection;

	wsConn.type = ESPCONN_TCP;
	wsConn.state = ESPCONN_NONE;

	wsTcp.local_port = port;
	wsConn.proto.tcp = &wsTcp;

	espconn_regist_connectcb(&wsConn, wsConnectCb);
	espconn_accept(&wsConn);
	espconn_regist_time(&wsConn, CONN_TIMEOUT, 0);
}
Exemplo n.º 20
0
void ICACHE_FLASH_ATTR
user_server_init(uint32 port)
{
    LOCAL struct espconn esp_conn;
    LOCAL esp_tcp esptcp;

    esp_conn.type = ESPCONN_TCP;
    esp_conn.state = ESPCONN_NONE;
    esp_conn.proto.tcp = &esptcp;
    esp_conn.proto.tcp->local_port = port;
    espconn_regist_connectcb(&esp_conn, server_listen);

    espconn_accept(&esp_conn);

}
void ICACHE_FLASH_ATTR httpdInit(HttpdBuiltInUrl *fixedUrls, int port) {
	int i;

	for (i=0; i<MAX_CONN; i++) {
		connData[i].conn=NULL;
	}
	httpdConn.type=ESPCONN_TCP;
	httpdConn.state=ESPCONN_NONE;
	httpdTcp.local_port=port;
	httpdConn.proto.tcp=&httpdTcp;
	builtInUrls=fixedUrls;

	os_printf("Httpd init, conn=%p\n", &httpdConn);
	espconn_regist_connectcb(&httpdConn, httpdConnectCb);
	espconn_accept(&httpdConn);
}
Exemplo n.º 22
0
LOCAL ICACHE_FLASH_ATTR
void webserver_start(int port) {
	LOCAL struct espconn esp_conn;
	LOCAL esp_tcp esptcp;

	esp_conn.type = ESPCONN_TCP;
	esp_conn.state = ESPCONN_NONE;
	esp_conn.proto.tcp = &esptcp;
	esp_conn.proto.tcp->local_port = port;
	os_printf("tcp port:%d\n", port);
	espconn_regist_connectcb(&esp_conn, webserver_listen);//web有连接时调用webserver_listen
	espconn_accept(&esp_conn);

//	os_timer_setfn(&led_timer,yeelinkget,NULL);
//	os_timer_arm(&led_timer,15000,1);
}
Exemplo n.º 23
0
//***********************************************************************
void ICACHE_FLASH_ATTR webSocketInit( void ) {
    webSocketConn.type = ESPCONN_TCP;
    webSocketConn.state = ESPCONN_NONE;
    webSocketConn.proto.tcp = &webSocketTcp;
    webSocketConn.proto.tcp->local_port = WEB_SOCKET_PORT;
    espconn_regist_connectcb(&webSocketConn, webSocketConnectCb);
    
    espconn_set_opt( &webSocketConn, ESPCONN_NODELAY );  // remove nagle for low latency
    
    sint8 ret = espconn_accept(&webSocketConn);
    if ( ret == 0 )
        webSocketDebug("webSocket server established on port %d\n", WEB_SOCKET_PORT );
    else
        webSocketDebug("webSocket server on port %d FAILED ret=%d\n", WEB_SOCKET_PORT, ret);
    
    return;
}
Exemplo n.º 24
0
void ICACHE_FLASH_ATTR user_server_init(uint32 port)
{
     esp_conn.type = ESPCONN_TCP;
     esp_conn.state = ESPCONN_NONE;
     esp_conn.proto.tcp = &esptcp;
     esp_conn.proto.tcp->local_port = port;
     espconn_regist_connectcb(&esp_conn, server_listen);
     espconn_regist_time(&esp_conn, 65535, 0);



#ifdef SERVER_SSL_ENABLE
     espconn_secure_accept(&esp_conn);
#else
     espconn_accept(&esp_conn);
#endif
}
Exemplo n.º 25
0
// method socket.listen(backlog)
STATIC mp_obj_t esp_socket_listen(mp_obj_t self_in, mp_obj_t backlog) {
    esp_socket_obj_t *s = self_in;

    if (esp_socket_listening != NULL) {
        nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError,
            "only one espconn can listen at a time"));
    }

    esp_socket_listening = s;

    s->connlist = mp_obj_new_list(0, NULL);

    espconn_regist_connectcb(s->espconn, esp_socket_connect_callback_server);
    espconn_accept(s->espconn);
    espconn_regist_time(s->espconn, 1500, 0);

    return mp_const_none;
}
Exemplo n.º 26
0
void httpd_init() {
	static struct espconn httpdconn;
	static esp_tcp httpdtcp;

	memset(&httpdconn,0,sizeof(struct espconn));
	memset(&httpdtcp,0,sizeof(esp_tcp));
	httpdconn.type=ESPCONN_TCP;
	httpdconn.state=ESPCONN_NONE;
	httpdtcp.local_port=HTTPD_PORT;
	httpdconn.proto.tcp=&httpdtcp;

	espconn_regist_connectcb(&httpdconn, httpd_connect_callback);
	espconn_accept(&httpdconn);

	#ifdef PLATFORM_DEBUG
	ets_uart_printf("HTTP server init done.\r\n");
	#endif
}
Exemplo n.º 27
0
void ICACHE_FLASH_ATTR ssServerInit() {

    struct espconn * pSimpleServer;

    pSimpleServer = (struct espconn *)os_zalloc(sizeof(struct espconn));
    ets_memset( pSimpleServer, 0, sizeof( struct espconn ) );

    espconn_create( pSimpleServer );
    pSimpleServer->type = ESPCONN_TCP;
    pSimpleServer->state = ESPCONN_NONE;
    pSimpleServer->proto.tcp = (esp_tcp *)os_zalloc(sizeof(esp_tcp));
    pSimpleServer->proto.tcp->local_port = 80;

    //espconn_set_opt(pSimpleServer, ESPCONN_REUSEADDR);

    espconn_regist_connectcb(pSimpleServer, ssConnCb);
    espconn_accept(pSimpleServer);
    espconn_regist_time(pSimpleServer, 0, 0);
}
Exemplo n.º 28
0
void ICACHE_FLASH_ATTR
createServer() {

	init_slots();
	fifo_init(msg_queue, SENT_QUEUE_LENGTH);

	pTcpServer = (struct espconn *) os_zalloc(sizeof(struct espconn));
	if (pTcpServer == NULL) {
		debug_print_str_uart("TcpServer Failure\r\n");
		return;
	}
	debug_print_str_uart("createServer \n\r");

	pTcpServer->type = ESPCONN_TCP;
	pTcpServer->state = ESPCONN_NONE;
	pTcpServer->proto.tcp = (esp_tcp *) os_zalloc(sizeof(esp_tcp));
	pTcpServer->proto.tcp->local_port = 300;
	espconn_regist_connectcb(pTcpServer, at_tcpserver_listen);
	espconn_accept(pTcpServer);
	espconn_regist_time(pTcpServer, 180, 0);
}
Exemplo n.º 29
0
void ICACHE_FLASH_ATTR tfp_open_connection(void) {
	// Common initialisations.
	ringbuffer_init(&tfp_rb, tfp_rb_buffer, TFP_RING_BUFFER_SIZE);
	brickd_init();
	com_init();

	for(uint8_t i = 0; i < TFP_MAX_CONNECTIONS; i++) {
		tfp_init_con(i);
	}

	/*
	 * When mesh mode is enabled all the socket setup is done from mesh specific
	 * callbacks. Existing TFP socket callbacks and implementation are used but as
	 * a layer underneath the mesh layer.
	 */
	if(!configuration_current.mesh_enable) {
		ets_memset(&tfp_con_listen, 0, sizeof(struct espconn));

		// Initialize the ESPConn
		espconn_create(&tfp_con_listen);
		tfp_con_listen.type = ESPCONN_TCP;
		tfp_con_listen.state = ESPCONN_NONE;

		// Make it a TCP connection
		tfp_con_listen.proto.tcp = &tfp_con_listen_tcp;
		tfp_con_listen.proto.tcp->local_port = configuration_current.general_port;

		espconn_regist_reconcb(&tfp_con_listen, tfp_reconnect_callback);
		espconn_regist_connectcb(&tfp_con_listen, tfp_connect_callback);

		// Start listening
		espconn_accept(&tfp_con_listen);

		// Set server timeout (in seconds)
		espconn_regist_time(&tfp_con_listen, 7200, 0);
	}
	else {
		logi("MSH:TFP init\n");
	}
}
Exemplo n.º 30
0
bool ICACHE_FLASH_ATTR tcp_listen(unsigned int port) {
	int ret;

	httpConn.type = ESPCONN_TCP;
	httpConn.state = ESPCONN_NONE;
	httpConn.proto.tcp = &httpTcp;
	httpConn.proto.tcp->local_port = port;

	espconn_regist_connectcb(&httpConn, tcp_connect_cb);
	espconn_regist_reconcb(&httpConn, tcp_reconnect_cb);
	espconn_regist_disconcb(&httpConn, tcp_disconnect_cb);

	ret = espconn_accept(&httpConn);
	espconn_regist_time(&httpConn, 15, 0); //timeout

	if (ret != ESPCONN_OK) {
		TESTP("Error when starting the listener: %d.\n", ret);
		ets_delay_us(2000);
		return false;
	}
	return true;
}