About new ESP-NOW functions on SDK 1.2.0
About new ESP-NOW functions on SDK 1.2.0
Postby Ivan » Mon Jul 06, 2015 9:55 am
Could you please kindly provide an example on how to use the new ESP-NOW functions on SDK 1.2.0?
I think I really need this for my project but just no idea on how to use it.
Thanks!
-
- Posts: 21
- Joined: Wed Jun 03, 2015 1:20 pm
Re: About new ESP-NOW functions on SDK 1.2.0
Postby parmar7725274 » Wed Jul 08, 2015 4:09 pm
I'm also interested. Let me know if you get something.
Thanks & Regards,
Prakash P.
Re: About new ESP-NOW functions on SDK 1.2.0
Postby ESP_Faye » Mon Jul 13, 2015 5:44 pm
Here is a simple example
Code: Select all
void ICACHE_FLASH_ATTR simple_cb(u8 *macaddr, u8 *data, u8 len)
{
int i;
u8 ack_buf[16];
u8 recv_buf[17];
os_printf("now from[");
for (i = 0; i < 6; i++)
os_printf("%02X, ", macaddr[i]);
os_printf(" len: %d]:", len);
os_bzero(recv_buf, 17);
os_memcpy(recv_buf, data, len<17?len:16);
show_buf2(data,len);
if (os_strncmp(data, "ACK", 3) == 0)
return;
os_sprintf(ack_buf, "ACK[%08x]", ack_count++);
esp_now_send(macaddr, ack_buf, os_strlen(ack_buf));
}
void user_init(void)
{
u8 key[16]= {0x33, 0x44, 0x33, 0x44, 0x33, 0x44, 0x33, 0x44, 0x33, 0x44, 0x33, 0x44, 0x33, 0x44, 0x33, 0x44};
u8 da1[6] = {0x18, 0xfe, 0x34, 0x97, 0xd5, 0xb1};
u8 da2[6] = {0x1a, 0xfe, 0x34, 0x97, 0xd5, 0xb1};
if (esp_now_init()==0) {
os_printf("esp_now init ok\n");
esp_now_register_recv_cb(simple_cb);
os_printf("dlink send to A cur chan %d\n", wifi_get_channel());
esp_now_set_self_role(1);
esp_now_add_peer(da1, 1, key, 16);
esp_now_add_peer(da2, 2, key, 16)
} else {
os_printf("esp_now init failed\n");
}
}
void ICACHE_FLASH_ATTR demo_send_(u8 *data, u8 len)
{
/* the demo will send to two devices which added by esp_now_add_peer() */
esp_now_send(NULL, data, len);
}
Re: About new ESP-NOW functions on SDK 1.2.0
Postby Ivan » Tue Jul 14, 2015 12:11 pm
Thanks for your response.
When I look at the example. It seems that the destination device must be an ESP8266 wifi module. Is that true?
Can I use ESP_NOW to send something to someone which is not an ESP device? like PC or mobile phone?
Re: About new ESP-NOW functions on SDK 1.2.0
Postby Ivan » Tue Jul 14, 2015 8:45 pm
Ok, got it. Thanks!
I have another question.
Can I use a broadcast mac like: u8 da1[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
as destination so I can discover an unknown ESP8266 device then add it as my peer(slave)?
Re: About new ESP-NOW functions on SDK 1.2.0
Postby ESP_Faye » Wed Jul 15, 2015 11:05 am
Sorry that ESP-NOW can not broadcast right now..
But we will think over your request, and let you know if there is any update.
Thanks for your interest in Espressif Systems and ESP8266 !
Re: About new ESP-NOW functions on SDK 1.2.0
Postby nice72 » Fri Jul 17, 2015 8:43 am
I have two questions.
1. What is the difference between this controller mode and slave mode?
2. And, When the channel of the own and peer are not the same, esp8266 can send a packet to the peer esp8266?
3. I would like to know the meaning of the return value is 0 esp_now_is_peer_exist.
When we received the return 0, that esp8266 is going to disappear?
Thanks,
Peter.
Re: About new ESP-NOW functions on SDK 1.2.0
Postby baoshi » Tue Jul 21, 2015 2:19 pm
I tried the code you provided.
It seems I always get -4 error from esp_now_add_peer call. It there any clue what I did wrongly? (esp_now_init and esp_now_set_self_role is ok).
Also, would you please give a little explanation what is CONTROLLER role and what is SLAVE role?
Thanks
Baoshi
Who is online
Users browsing this forum: No registered users and 83 guests
Login
Newbies Start Here
Are you new to ESP8266?
Unsure what to do?
Dunno where to start?
Start right here!
Latest SDK
Documentation
Complete listing of the official ESP8266 related documentation release by ESPRESSIF!
Must read here!
- All times are UTC+08:00
- Top
- Delete all board cookies
About Us
Espressif Systems is a fabless semiconductor company providing cutting-edge low power WiFi SoCs and wireless solutions for wireless communications and Internet of Things applications. We are the manufacturer of ESP8266EX.