Challenge: Simultaneous Wifi Access

challenge
events

#1

Community members!

We need your help! At meetups, when there are 25 people in the room with both boards and laptops logging in to the local router, we often clog the network. @iotcommu2017 has suggested that simultaneous WiFi access from multiple boards could be solved by changing the WiFi channel frequency. Good idea!

We’re offering a $50 Amazon gift card and a free AMS Environmental sensor if someone will rewrite the Smart Chef project code. We need this before Friday, June 2, for the next meetup.

From @iotcommu2017:

Most of the demo application provisioning code use channel 1 and once provision done normal wifi access there is no channel defined.

Like below in provision mode (Access point mode)

g_provision_info.channel = 1.

if possible some one can change this like below in client mode

g_provision_info.channel = (uint8_t)(rand() % MAX_NUM_WiFi_CHANNLES); //random channel

define MAX_NUM_WiFi_CHANNLES 9 or 11

Keeping each device random channels may free up some of the issue.

smartchef project code can be modified like above. But every one download from Renesas sites its worthwhile ask them to change.

For information on getting the Smart Chef Demo source and building it with e2 Studio, see this tutorial:

To win the challenge, you need to submit both the source and a working binary.

Reply here or DM me @jcasman or email me at jcasman@oppkey.com


Learn IoT MeetUp - June 5 in San Jose
#2

Hi Jesse,

I ran a quick test on both of my S3A7 boards, and every time they entered provisioning mode, they used channel 6. Would you be willing to check several of your boards and see what channel they use?

After a little digging, I found the code that sets the channel used in provisioning mode. It’s in the file “net_thread_entry.c”

Here is the relevant section which starts around line 327. I have been changing my code a little, so the line number may vary by a few places.

int seed = 0;
for (unsigned int i = 0; i < sizeof(p_fmi_product_info->unique_id); i++)
    seed = p_fmi_product_info->unique_id[i] + (seed << 6) + (seed << 16) - seed;
srand((unsigned int)seed);

char supported_chars[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_.";
char supported_chars_password[] = "0123456789";
char wifi_ssid[16] = "iot-wifi-";
char wifi_password[11];
// TODO: for more "security", skip a random number of sequence
for (unsigned int j = strlen(wifi_ssid); j < sizeof(wifi_ssid) - 1; j++)
    wifi_ssid[j] = supported_chars[((unsigned int)rand()) % (sizeof(supported_chars) - 1)];
wifi_ssid[sizeof(wifi_ssid) - 1] = '\0';
for (unsigned int j = 0; j < sizeof(wifi_password) - 1; j++)
    wifi_password[j] = supported_chars_password[((unsigned int)rand()) % (sizeof(supported_chars_password) - 1)];
wifi_password[sizeof(wifi_password) - 1] = '\0';
strcpy((char *)&prov.ssid[0], wifi_ssid);
strcpy((char *)&prov.key[0], wifi_password);
srand (9);
prov.channel = !(rand() % 3) ? 1 : !(rand() % 2) ? 6 : 11;

This line:

srand((unsigned int)seed);

seeds the random number generator with a number which should be unique to a particular board.

The last line in the code snippet:

prov.channel = !(rand() % 3) ? 1 : !(rand() % 2) ? 6 : 11;

should result in 1/3 of boards provisioned using channel 1, channel 6, and channel 11 respectively. In a large population of boards 1/3 should use each channel, but perhaps there’s a problem with the seed function? If all of your boards use channel 6, then we know the random channel selection isn’t working as intended.

If you find that all of your boards are provisioning on the same channel, I could very quickly create a channel 1 binary, channel 6 binary, and channel 11 binary and you could program 1/3 of your boards with each. All you have to do is replace the random function above with a line like this:

prov.channel = 1; //or 6 or 11 etc.

I verified that this works.

If you really wanted this to be random so that each time you provision the same board it uses a random channel, you’d have to add a general purpose timer and use timer ticks to seed the random function.

Also, my understanding of the way wifi works is that there really are only 3 channels – 1,6,11, and that all of the others are just sub channels of one of these.

Let me know what you see on your boards!

Dan


#3

Dan, this is great, really helpful. I can test some boards that I have later today, probably early afternoon. Back in touch then with my results.


#4

I’ll try and test it as well


#5

Sorry for late jump in, just like to share my comments

As Dan mentioned above,

on software not really getting perfect random number every reboot. Mostly same set of numbers.

Instead of go for random we can try to derive channel number based boards unique number. Renesas board has this information. We can see this part of random SSID/password generation code. Anyway below function can give those details.

To get board details,
//DEVVICE UNIQUE id
fmi_unique_id_t devi_uniq_id;
fmi_product_info_t *prd_info = NULL;

g_fmi.p_api->uniqueIdGet(&devi_uniq_id);
g_fmi.p_api->productInfoGet(&prd_info);

Example random SSID generation using device ID
//srand (time(NULL));
snprintf(g_auto_gen_prov_ssid, sizeof(g_auto_gen_prov_ssid), “iot-wifi-%u%u”,
(uint8_t)devi_uniq_id.unique_id[2], (uint8_t)devi_uniq_id.unique_id[3]);

I think for demo purpose building the application in group of channels might be good option because we control the channels even though bit pain to build and manage the application building.


#6

@jcasman can you test these:

S3_IOT_smartchef_wifi_ch_1.srec (2.9 MB)
S3_IOT_smartchef_wifi_ch_6.srec (2.9 MB)
S3_IOT_smartchef_wifi_ch_11.srec (2.9 MB)

I transferred one to my board, but have not tested the WiFi channel. If you have a moment:

  1. transfer each binary to a separate s3a7 board
  2. configure each board to connect to your local home router
  3. log into your router to check the channel it’s using

Does anyone know of another way to see what channel it’s using?

I need to step out for a few hours, but will try this myself later.


#7

I’m in a waiting room now and can’t test this, but it appears that a wifi scanner may show channels in use.


#8

if you add below code we can display channel number used for that connection/board

ssp_err_t result = SSP_ERR_IN_USE;
sf_wifi_provisioning_t g_active_provision_info;

while (result != SSP_SUCCESS) {
    result = g_sf_wifi0.p_api->provisioningGet(g_sf_wifi0.p_ctrl, &g_active_provision_info);
}
printf("channel used %d", g_active_provision_info.channel); //connected channel number connected with router.

I checked one of your binary, but I don’t have channel information on my router control panel so don’t know which channel is assigned at that time.

I checked with S7G2 board with my application using above code. I think lot more going on… (I may be wrong…)

I fixed the channel 3, 6 before calling Set function.

    result = g_sf_wifi0.p_api->provisioningSet(g_sf_wifi0.p_ctrl, &g_provision_info);

After successful connection with my router (TP-LINK C7)
channel actually connected is 1 not 3 or 6.

What it means : Looks like Router is managing the channel number depends on number of device and frequency used or free.

If this is the case work need to be at Router side not on the board what we are doing. This is my current understanding based on my one device test (I have almost 10 devices connected with my router and never had a problem). We need to think about router what is used on the demo setup…?

Mariya


#9

Hi All,

I used a linux tool on my raspberry pi to scan local wifi hotspots. In a terminal window, type:

sudo iwlist wlan0 scan

It then lists a bunch of information including channel number about all hot spots in range.

When I did set a channel to some arbitrary number (3 for example) the scanner always confirmed the channel, so I know that works on the S3A7 board. It may well be that the random selection code already present works as advertised. Because of the pseudo-random nature of the c rand() function and the fixed seed used in the code each board will always choose the same channel. In other words, if a board uses channel 11, it will always use channel 11. That is why it is worth checking what you have in case you got a series of boards that all choose the same channel. Our deterministic approach of assigning 1/3 of the boards to each different channel may help, but even 8 boards running on a channel may be too many.

I had no trouble using my board at the last meetup, because I pre-configured it to connect to a wifi hotspot on my phone thus bypassing the poor over-stressed router. That may also be a helpful approach for some people.

Dan


#10

Exactly what I was looking for!! Thanks. There’s much more information here. I’m doing more tests now. It looks like we can control the WiFi channel of the board if we need to.

Hope you and Mariya have a great weekend. This was super helpful.


#11

Have a great weekend yourself! I just tested each of your files twice and they worked as expected. Did you find that many of your boards were using the same channel?

Dan


#12

Jesse has the boards at his office and I only have a few boards for testing. He grabs all the fun. I’m finding this exercise interesting and I’m learning something. :slight_smile:

Though, I think that I’m reaching the conclusion that the channel is assigned by hotspot. When the S3A7 is configured as a hotspot, we can control the channel used in the initial board provisioning. However, when the S3A7 connects to the Internet router, I suspect that the WiFi channel is controlled by the router. I’m not sure about this and am still trying to verify this.

I can use iwlist to scan for hotspots. However, I can’t figure out how to identify what channel is used when the S3A7 board connects to the Internet WiFi router. I’m assuming that the router will assign a channel randomly and we can’t control the assignment.

I’ll ponder this and the way of IoT over the weekend.


#13

I believe you are correct. All of my posts relate only to provisioning mode when the board is the hot spot. I assumed that was our problem. Under those circumstances, we can control the channel. When the board is just connecting to a router, the router chooses according to its configuration

There is nothing we can do once the board has connected to a router. The router has control! Once everyone is provisioned, it’s just like we are all sitting at a crowded Starbucks trying to use their wifi.

Dan


#14

My comment also based on Client mode where router control the channel number and frequency.

To control router side issue how about set up few SKS7G2 board as router?. We can build a application for this board with LAN port connected with internet (router) and GT202 WiFi as hotspot with fixed channel number for each board.

I think these board can support decent network traffic(simply packet forwarding) .

As meetup is close by so taking this setup may not be good idea right now.
Thanks
Mariya


#15

Few raspberry pi can be setup as hotspot as well.


#16

I’m going to look into running an Ethernet cable to the problem table to try and set up an additional WiFi router on the table. :satellite:


#17

We have a WINNER! Actually, two winners, since we had two community members @Dan and @iotcommu2017 really jump in and help on this. So, we’re splitting the prize down the middle, $25 each.

Amazon gift cards being sent to your email addresses now.

We’ll see how it works for real with a room full of users on Monday, but I’m confident this will be a big improvement to the whole provisioning part of the meetup for attendees.

Super big thank you to Dan and Mariya!


#18

Hello Jesse

Thank you for Amazon Gift card. I am glad I could give some suggestions (need to wait and see WiFi really help some level!!). See you soon.

Mariya


#19

Thanks a ton, Mariya. Really appreciate the help. Looking forward to meetin you tonight.


#20

Hello to all

Just wanted to give update related with WiFi access problem.

If board is running in “AP” mode then fixing channel might be Okay, as we know already.

If board is in “Client mode” (i.e. trying connect to router) then fixing WiFi channel number cause problem (observed in SSP1.2.1).

For example like this
g_provision_info.channel = (uint8_t)11;

It does not matter if you flash the board(works) every time, but if you connect to other USB power source (like battery pack) OR Reset the board WiFi access won’t work.

Mariya