About new ESP-NOW functions on SDK 1.2.0

ESP_Faye
Posts: 1642
Joined: Mon Oct 27, 2014 11:08 am

Re: About new ESP-NOW functions on SDK 1.2.0

Postby ESP_Faye » Tue Jul 21, 2015 5:21 pm

Hi,

1、The mode will effect the interface selection. And it can be used for judge some condition. We recommend to use slave mode for ESP8266 softAP or sta+softAP mode, controller mode for ESP8266 station mode.


2. If you want to send ESP-NOW package, the app layer must keep the channel in the same.

ESP-NOW is for smart-light project, usually we use device LIGHT on slave mode, device SWITCH on controller mode.

baoshi
Posts: 23
Joined: Tue Dec 02, 2014 8:35 pm

Re: About new ESP-NOW functions on SDK 1.2.0

Postby baoshi » Tue Jul 21, 2015 9:55 pm

Hi Faye:

I have this piece of code:

Code: Select all

void user_init(void)
{
  int rc;
  // Configure the UART
  uart_init(BIT_RATE_115200, BIT_RATE_115200);
  ets_uart_printf("\n\n");
 
  wifi_set_opmode(1); // STATION
 
  u8 key[16]= {0x33, 0x44, 0x33, 0x44, 0x33, 0x44, 0x33, 0x44, 0x33, 0x44, 0x33, 0x44, 0x33, 0x44, 0x33, 0x44};
  u8 local[6] = {0x18, 0xfe, 0x34, 0x9c, 0x3e, 0xf0};   // This module in STATION mode
  u8 remote[6] = {0x1a, 0xfe, 0x34, 0x9c, 0x3e, 0xe5};   // Another modules in SOFTAP mode
 
  if (esp_now_init()==0)
  {
    ets_uart_printf("esp_now init ok\n");
    esp_now_register_recv_cb(simple_cb);
    ets_uart_printf("dlink send to A cur chan %d\n", wifi_get_channel());
    if (rc = esp_now_set_self_role(1)) ets_uart_printf("set_self_role failed %d\r\n", rc); // CONTROLLER
    if (rc = esp_now_add_peer(local, 1, key, 16)) ets_uart_printf("add_peer failed %d\r\n", rc);
    if (rc = esp_now_add_peer(remote, 2, key, 16)) ets_uart_printf("add_peer failed %d\r\n", rc);
  } else
  {
    ets_uart_printf("esp_now init failed\n");
  }
 
  // Set up a timer to send the message
  os_timer_disarm(&hello_timer);
  os_timer_setfn(&hello_timer, (os_timer_func_t *)hello_cb, (void *)0);
  os_timer_arm(&hello_timer, DELAY, 1);
}

LOCAL void ICACHE_FLASH_ATTR hello_cb(void *arg)
{
  u8 all_cnt, encrypt_cnt;

  if (esp_now_get_cnt_info(&all_cnt, &encrypt_cnt))
  ets_uart_printf("get_cnt_info failed\r\n");
  ets_uart_printf("client:%d, encrypted client:%d\r\n", all_cnt, encrypt_cnt);
  ets_uart_printf("send ");
  if (esp_now_send(NULL, "Hello", 6))
    ets_uart_printf("fail\r\n");
  else
    ets_uart_printf("ok\r\n");
}


I receive -4 error for all the esp_now_add_peer calls.
The print in hello_cb is client:0, encrypted client:0. But esp_now_send seems successful.

Any idea?

Thanks

ESP_Faye
Posts: 1642
Joined: Mon Oct 27, 2014 11:08 am

Re: About new ESP-NOW functions on SDK 1.2.0

Postby ESP_Faye » Fri Jul 24, 2015 3:13 pm

Hi, baoshi,

1、I receive -4 error for all the esp_now_add_peer calls.
-> esp_now_add_peer needs 5 parameters, you lost the parameter channel.

2、The print in hello_cb is client:0, encrypted client:0. But esp_now_send seems successful.
-> This is because that esp_now_add_peer failed in question 1. We will optimize the return value of ESP-NOW APIs in next SDK.

Thanks for your interest in Espressif Systems and ESP8266 !

baoshi
Posts: 23
Joined: Tue Dec 02, 2014 8:35 pm

Re: About new ESP-NOW functions on SDK 1.2.0

Postby baoshi » Fri Jul 24, 2015 9:30 pm

Thanks Faye, that works.
I made a stupid mistake of not #include <espnow.h> in the begin. The compiler also never gives an error, strange.

User avatar
kolban
Posts: 131
Joined: Tue Jun 16, 2015 1:09 pm
Location: Fort Worth, Texas, USA

Re: About new ESP-NOW functions on SDK 1.2.0

Postby kolban » Fri Jul 24, 2015 9:38 pm

Howdy guys,
I am still very interested to learn a basic question ... "What are these new functions?" What are their purpose? I haven't yet been able to find any documentation on what "ESP-NOW" actually does for me? Can some kind soul offer a brief explanation?

Neil

Lurch
Posts: 7
Joined: Thu Jul 02, 2015 4:59 am

Re: About new ESP-NOW functions on SDK 1.2.0

Postby Lurch » Sat Jul 25, 2015 1:41 am

They are described in 2C-ESP8266__SDK__Programming Guide__EN_v1.1.2.pdf
They are something like a poor man's MQTT for sending short messages between ESP8266 with very little overhead.
All ESP8266s must be on the same network, so this could be for sending data from sensors.

parmar7725274
Posts: 21
Joined: Wed Jun 03, 2015 1:20 pm

Re: About new ESP-NOW functions on SDK 1.2.0

Postby parmar7725274 » Tue Oct 06, 2015 2:51 am

Hi Faye, Baoshi and ALL !!

I have two ESP modules. ESP - 01 and ESP 12q. I configured both of modules as follows :

ESP - 01 : mac address - 18:fe:34:9e:18:21
- set mode - STATION
- set role - CONTROLLER ( 1 )
- registered send and receive callback
- Add peer ESP-12q (mac - 5c:cf:7f:00:da:1d ) , role - SLAVE ( 02 ), channel - 1

ESP - 12 : mac address - 5c:cf:7f:00:da:1d
- set mode - STATION+AP
- set role - SLAVE ( 2 )
- registered send and receive callback
- add peer ESP-01 (mac - 18:fe:34:9e:18:21 ), role - CONTROLLER( 1 ), channel - 1

I check the return value of each function call and I get success.

Problem :-
When I'm sending packet from ESP - 01 using esp_now_send function. I'm getting success and send call back is called but On other end( ESP - 12q ) I'm not getting any Packet.

Please help me to solve this.

Thanks & Regards,
Prakash Parmar

koltegirish97
Posts: 11
Joined: Fri Jul 31, 2015 2:12 pm

Re: About new ESP-NOW functions on SDK 1.2.0

Postby koltegirish97 » Wed Oct 21, 2015 2:05 pm

Hello Guys,
Can anybody provide the sample code for ESP-NOW FUNCTIONS that I can get an idea to build communication between two esp modules.As I refer the code but it shows compilation error.

User avatar
kolban
Posts: 131
Joined: Tue Jun 16, 2015 1:09 pm
Location: Fort Worth, Texas, USA

Re: About new ESP-NOW functions on SDK 1.2.0

Postby kolban » Thu Oct 22, 2015 10:14 pm

Is there a design or architecture document/description for ESP-NOW? For example, something that describes the concept of controller vs slave?

koltegirish97
Posts: 11
Joined: Fri Jul 31, 2015 2:12 pm

Re: About new ESP-NOW functions on SDK 1.2.0

Postby koltegirish97 » Tue Oct 27, 2015 8:38 pm

Hello Everyone,
After compiling code of mesh it shows following error .Anybody knows how to resolve it.
LD build/app.out
c:/Espressif/ESP8266_SDK/lib\libmain.a(app_main.o): In function `user_uart_wait_tx_fifo_empty':
(.irom0.text+0x598): undefined reference to `user_init'
c:/Espressif/ESP8266_SDK/lib\libmain.a(app_main.o): In function `user_rf_pre_init':
(.irom0.text+0x804): undefined reference to `user_init'
collect2.exe: error: ld returned 1 exit status
C:/Users/Girish/worksorg/mesh/Makefile:187: recipe for target 'build/app.out' failed
mingw32-make.exe: *** [build/app.out] Error 1

18:05:56 Build Finished (took 1s.205ms)

Who is online

Users browsing this forum: Google [Bot] and 9 guests