Trying to use mesh lib
Posted: Wed Oct 21, 2015 2:55 am
Hello,
I am trying to use mesh lib on eclipse.
Please go through my code and its output below. The code gets compiled and burned successfully. The ESP forms an AP. I connected a PC to it and a mobile to it and successfully pinged from PC to mobile. I am not getting the data at PC as TCP connection is not getting formed when I have statically assigned the IP 2.255.255.7 to the PC.
Now, when I burned another ESP with the code, I did not get any AP from it. How do I check whether my mesh is working correctly? Is my way of using mesh with TCP espconn correct?
----------------------------------------------
#include <ets_sys.h>
#include <osapi.h>
#include <os_type.h>
#include <gpio.h>
#include "driver/uart.h"
#include "mesh.h"
#define DELAY 1000 /* milliseconds */
#define REMOTE_PORT 8888
#define REMOTE_IP "2.255.255.7"
LOCAL os_timer_t hello_timer;
extern int ets_uart_printf(const char *fmt, ...);
struct espconn conn1;
esp_tcp tcp1;
void makeConnection() {
conn1.type = ESPCONN_TCP;
conn1.state = ESPCONN_NONE;
conn1.proto.tcp = &tcp1;
conn1.proto.tcp->remote_port = REMOTE_PORT;
*((uint32 *)conn1.proto.tcp->remote_ip) = ipaddr_addr(REMOTE_IP);
uint8_t pdata[3] = {4,5,6};
ets_uart_printf("We have asked for a mesh connection! Status: %d\n", espconn_mesh_connect(&conn1));
ets_uart_printf("espconn mesh get status after asking for connection: %d\n", espconn_mesh_get_status());
ets_uart_printf("espconn mesh sent status: %d\n", espconn_mesh_sent(&conn1, pdata, 3));
ets_uart_printf("espconn mesh get status after mesh sent: %d\n", espconn_mesh_get_status());
ets_uart_printf("We have closed a mesh connection! Status: %d\n", espconn_mesh_disconnect(&conn1));
}
void enable_cb()
{
ets_uart_printf("espconn mesh get status after mesh enable: %d\n", espconn_mesh_get_status());
makeConnection();
}
LOCAL void ICACHE_FLASH_ATTR hello_cb(void *arg)
{
ets_uart_printf("Hello World!\r\n");
makeConnection();
}
void init(void)
{
enum mesh_type type = MESH_ONLINE;
espconn_mesh_enable(enable_cb, type);
}
void user_rf_pre_init(void)
{
}
void user_init(void)
{
// Configure the UART
uart_init(BIT_RATE_115200, BIT_RATE_115200);
system_init_done_cb(init);
// Set up a timer to send the message
// os_timer_disarm(ETSTimer *ptimer)
os_timer_disarm(&hello_timer);
// os_timer_setfn(ETSTimer *ptimer, ETSTimerFunc *pfunction, void *parg)
os_timer_setfn(&hello_timer, (os_timer_func_t *)hello_cb, (void *)0);
// void os_timer_arm(ETSTimer *ptimer,uint32_t milliseconds, bool repeat_flag)
os_timer_arm(&hello_timer, DELAY, 1);
}
----------------------------------------------
Output:
.
.
.
Hello World!
We have asked for a mesh connection! Status: 0
espconn mesh get status after asking for connection: 3
espconn mesh sent status: 0
espconn mesh get status after mesh sent: 3
We have closed a mesh connection! Status: 0
Hello World!
We have asked for a mesh connection! Status: 0
espconn mesh get status after asking for connection: 3
espconn mesh sent status: 0
espconn mesh get status after mesh sent: 3
We have closed a mesh connection! Status: 0
.
.
.
----------------------------------------------
Kindly, reply.
Thanking you,
Yours sincerely,
Shubham Jain
I am trying to use mesh lib on eclipse.
Please go through my code and its output below. The code gets compiled and burned successfully. The ESP forms an AP. I connected a PC to it and a mobile to it and successfully pinged from PC to mobile. I am not getting the data at PC as TCP connection is not getting formed when I have statically assigned the IP 2.255.255.7 to the PC.
Now, when I burned another ESP with the code, I did not get any AP from it. How do I check whether my mesh is working correctly? Is my way of using mesh with TCP espconn correct?
----------------------------------------------
#include <ets_sys.h>
#include <osapi.h>
#include <os_type.h>
#include <gpio.h>
#include "driver/uart.h"
#include "mesh.h"
#define DELAY 1000 /* milliseconds */
#define REMOTE_PORT 8888
#define REMOTE_IP "2.255.255.7"
LOCAL os_timer_t hello_timer;
extern int ets_uart_printf(const char *fmt, ...);
struct espconn conn1;
esp_tcp tcp1;
void makeConnection() {
conn1.type = ESPCONN_TCP;
conn1.state = ESPCONN_NONE;
conn1.proto.tcp = &tcp1;
conn1.proto.tcp->remote_port = REMOTE_PORT;
*((uint32 *)conn1.proto.tcp->remote_ip) = ipaddr_addr(REMOTE_IP);
uint8_t pdata[3] = {4,5,6};
ets_uart_printf("We have asked for a mesh connection! Status: %d\n", espconn_mesh_connect(&conn1));
ets_uart_printf("espconn mesh get status after asking for connection: %d\n", espconn_mesh_get_status());
ets_uart_printf("espconn mesh sent status: %d\n", espconn_mesh_sent(&conn1, pdata, 3));
ets_uart_printf("espconn mesh get status after mesh sent: %d\n", espconn_mesh_get_status());
ets_uart_printf("We have closed a mesh connection! Status: %d\n", espconn_mesh_disconnect(&conn1));
}
void enable_cb()
{
ets_uart_printf("espconn mesh get status after mesh enable: %d\n", espconn_mesh_get_status());
makeConnection();
}
LOCAL void ICACHE_FLASH_ATTR hello_cb(void *arg)
{
ets_uart_printf("Hello World!\r\n");
makeConnection();
}
void init(void)
{
enum mesh_type type = MESH_ONLINE;
espconn_mesh_enable(enable_cb, type);
}
void user_rf_pre_init(void)
{
}
void user_init(void)
{
// Configure the UART
uart_init(BIT_RATE_115200, BIT_RATE_115200);
system_init_done_cb(init);
// Set up a timer to send the message
// os_timer_disarm(ETSTimer *ptimer)
os_timer_disarm(&hello_timer);
// os_timer_setfn(ETSTimer *ptimer, ETSTimerFunc *pfunction, void *parg)
os_timer_setfn(&hello_timer, (os_timer_func_t *)hello_cb, (void *)0);
// void os_timer_arm(ETSTimer *ptimer,uint32_t milliseconds, bool repeat_flag)
os_timer_arm(&hello_timer, DELAY, 1);
}
----------------------------------------------
Output:
.
.
.
Hello World!
We have asked for a mesh connection! Status: 0
espconn mesh get status after asking for connection: 3
espconn mesh sent status: 0
espconn mesh get status after mesh sent: 3
We have closed a mesh connection! Status: 0
Hello World!
We have asked for a mesh connection! Status: 0
espconn mesh get status after asking for connection: 3
espconn mesh sent status: 0
espconn mesh get status after mesh sent: 3
We have closed a mesh connection! Status: 0
.
.
.
----------------------------------------------
Kindly, reply.
Thanking you,
Yours sincerely,
Shubham Jain