Wifi established = led blink

Hello All,

rtlduino + example wlan_repeater
can anyone give a recipe on how to add to this when the rtlduino makes a successful connection to the AP (drone) the led builtin will dimly blink?

Thank You

Brcisna,
Are you using Arduino or SDK.
If it is Ardunio, you can use GTIMER or use millis() function

#include <GTimer.h>
#include <WiFi.h>

char ssid[] = "yourNetwork";     //  your network SSID (name)
char pass[] = "secretPassword";  // your network password

int led_status = 0;     // the Wifi radio's status
void myhandler(uint32_t data)  {
    //check wifi status
    if(WiFi.status() == WL_CONNECTED ) {
        led_status ^=1;
    } 
    else {
        led_status = 0; //if WiFi disconnected
    }
      //check wifi status, if connected AP , the led is flash , otherwirse led is dark
    digitalWrite(LED_BUILTIN, led_status); 
}
void setup() {
   //Initialize serial and wait for port to open:
    Serial.begin(115200);
    while (!Serial) {
        ; // wait for serial port to connect. Needed for native USB port only
    }

    // check for the presence of the shield:
    if (WiFi.status() == WL_NO_SHIELD) {
        Serial.println("WiFi shield not present");
        // don't continue:
        while (true);
    }

    // attempt to connect to Wifi network:
 
    WiFi.begin(ssid, pass);
    // initialize digital pin LED_BUILTIN as an output.
    pinMode(LED_BUILTIN, OUTPUT);
    // timerid 0, period 100ms invoke myhander
    GTimer.begin(0, (1 * 100 * 1000), myhandler);

}
void loop(void)
{


}

Hi Alphi,

Thank You for this
Am using the ambd SDK,as this is how I have the rtlduino running as wlan_repeater.
How can I add the portion you posted along with the existing wlan_repater . bin file?
I am not smart at all on coding,it goes without saying.
If i add though the Ardion IDE, the file you posted,it will overwrite my existing flash,will it not?

Thank You

Hi Alphi,

Is it all possible to edit the examples wlan_repeater.c file in ambd_sdk and convert the code you have here.
Have been trying to read a lot on the c coding but not smart enough to figure this out.

Thanks

1 Like

i will try to added wifi blink code for SDK

Thank You Alphi,
You’re a scholar.

Bcinna,
Add the simplest code(but i not tested), create a Task when connected online, and blink. Of course, you can use callback event, for example
wifi_reg_event_handler(WIFI_EVENT_IP_CHANGED, (rtw_event_handler_t)wifi_ip_changed_hdl, NULL);

//some code

wifi_indication(WIFI_EVENT_IP_CHANGED, NULL,0, 0);
wifi_unreg_event_handler(WIFI_EVENT_IP_CHANGED,(rtw_event_handler_t) wifi_ip_changed_hdl);

#include <platform_opts.h>
#include "FreeRTOS.h"
#include "task.h"
#include <platform/platform_stdlib.h>

#include "wifi_constants.h"
#include "wifi_structures.h"
#include "lwip_netconf.h"
#include "wifi_conf.h"

#if CONFIG_EXAMPLE_WLAN_FAST_CONNECT
typedef int (*init_done_ptr)(void);
extern init_done_ptr p_wlan_init_done_callback;
extern int wlan_init_done_callback();
#endif
#if CONFIG_BRIDGE
extern void bridgeif_set_mac_init(char *bmac);
extern void bridgeif_add_port_ap_netif(void);
extern void bridgeif_add_port_sta_netif(void);
#endif

#if CONFIG_EXAMPLE_WLAN_REPEATER

#if CONFIG_LWIP_LAYER
extern struct netif xnetif[NET_IF_NUM]; 
#endif

/**
 * @brief  Wi-Fi example for mode switch case: Mode switching between concurrent mode and STA and add to bridge.
 * @note  Process Flow:
 *              - Disable Wi-Fi
 *              - Enable Wi-Fi with concurrent (STA + AP) mode
 *              - Start AP
 *              - Check AP running
 *              - Connect to AP using STA mode
 */
static void example_wlan_repeater_thread(void *param)
{
	/* To avoid gcc warnings */
	( void ) param;

	// Wait for other task stable.
	vTaskDelay(4000);

	/*********************************************************************************
	*	1. Enable Wi-Fi with concurrent (STA + AP) mode
	*********************************************************************************/
	printf("\n\r[WLAN_REPEATER_EXAMPLE] Enable Wi-Fi with concurrent (STA + AP) mode\n");

	/*********************************************************************************
	*	1-1. Disable Wi-Fi
	*********************************************************************************/
	printf("\n\r[WLAN_REPEATER_EXAMPLE] Disable Wi-Fi\n");
	wifi_off();
	vTaskDelay(20);

	/*********************************************************************************
	*	1-2. Enable Wi-Fi with STA + AP mode
	*********************************************************************************/
	printf("\n\r[WLAN_REPEATER_EXAMPLE] Enable Wi-Fi with STA + AP mode\n");
	if(wifi_on(RTW_MODE_STA_AP) < 0){
		printf("\n\r[WLAN_REPEATER_EXAMPLE] ERROR: wifi_on failed\n");
		return;
	}

	uint8_t *mac = LwIP_GetMAC(&xnetif[0]);
	bridgeif_set_mac_init(mac);
	bridgeif_add_port_sta_netif();
	bridgeif_add_port_ap_netif();

	/*********************************************************************************
	*	1-3. Start AP
	*********************************************************************************/
	printf("\n\r[WLAN_REPEATER_EXAMPLE] Start AP\n");
	char *ssid = "AmebaRPT";
	char *password = "12345678";	// NULL for RTW_SECURITY_OPEN
	int channel = 6;

	if(wifi_start_ap(ssid, (password)?RTW_SECURITY_WPA2_AES_PSK:RTW_SECURITY_OPEN, password, strlen(ssid), (password)?strlen(password):0, channel) < 0) {
		printf("\n\r[WLAN_REPEATER_EXAMPLE] ERROR: wifi_start_ap failed\n");
		return;
	}

	/*********************************************************************************
	*	1-4. Check AP running
	*********************************************************************************/
	printf("\n\r[WLAN_REPEATER_EXAMPLE] Check AP running\n");
	int timeout = 20;
	while(1) {
		char essid[33];
		if(wext_get_ssid(WLAN1_NAME, (unsigned char *) essid) > 0) {
			if(strcmp((const char *) essid, (const char *)ssid) == 0) {
				printf("\n\r[WLAN_REPEATER_EXAMPLE] %s started\n", ssid);
				break;
			}
		}
		if(timeout == 0) {
			printf("\n\r[WLAN_REPEATER_EXAMPLE] ERROR: Start AP timeout\n");
			return;
		}
		vTaskDelay(1 * configTICK_RATE_HZ);
		timeout --;
	}

	/*********************************************************************************
	*	1-5. Connect to AP using STA mode and start DHCP client
	*********************************************************************************/
	printf("\n\r[WLAN_REPEATER_EXAMPLE] Connect to AP\n");
	if(p_wlan_init_done_callback)
		p_wlan_init_done_callback();

	if(xTaskCreate(example_wifi_status_thread, ((const char*)"example_wlan_status"), 1024, NULL, tskIDLE_PRIORITY + 2, NULL) != pdPASS)
		printf("\n\r%s xTaskCreate failed\n", __FUNCTION__);

	vTaskDelete(NULL);
}
void example_wifi_status_thread(void *param)
{
	uint8_t led = 0;
	uint8_t i;
	for(i=0;i<10;i++) {
		gpio_write(&gpio_wlan_act, led);
		led^=1;
		vTaskDelay(1 * configTICK_RATE_HZ);

	}
	vTaskDelete(NULL);

}
void example_wlan_repeater(char* id){
	if(xTaskCreate(example_wlan_repeater_thread, ((const char*)"example_wlan_repeater_thread"), 1024, NULL, tskIDLE_PRIORITY + 1, NULL) != pdPASS)
		printf("\n\r%s xTaskCreate failed\n", __FUNCTION__);
}

#endif /* CONFIG_EXAMPLE_WLAN_REPEATER */

Hi Alphi,

Appreciate you doing this.
Unfortunately,I dont understand what I need to do to compile this,or add to existing example_wlan_repeater.c file ?
I am very dense on this but try to learn a little of how to do it. , sorry

Thank You

Hi Brcisna,
Did you check the status of the LEDs? I am using wifi_led in the example and it only blinks. In the example, should the LED blink even when the data is exchanged?

1 Like

Hi Alphi,

I do not see an wifi_led directory in the ‘examples’ directory in the ambd_sdk?
maybe i am looking in wrong location in the sdk?
What I would like ideally,is power on repeater on side of drone, once the repeater is connected to drone AP, is the repeater led just blinks slowly,at this point we can have the drone take off. Hope this makes sense.

Thank You

Hi Alphi,

The three lines of code you gave to make the led blink below //some code----> in the previous post you made here.
Were would i put this into the existing example_wlan_repeater.c file?
I know nothing about coding syntax,sorry

Thank You

Hi Brcisna,
This is another way to call the SDK Event Callback method to determine when the function is called while connected.

Please also make sure that the LED is working properly. You can light up the LED when you power up

1 Like

Hi Alphi,

Thank You for trying to help me out.
No the led on this never does light up,even when powering on. Wasn’t sure the builtin led was suppose to light at power up.

I asked earlier, How do i write in the code you gave for an example for the led to light up at AP connection?
Am lost on how to add this type of code to an existing .c file
AKA: example_wlan_repeater.c

Thanks again

Hi, brcisna
Well, I will check which LED RTLDunio actually uses and test if it will brighten up when connected. Anyway it is still necessary to understand how to use the SDK and call the API

1 Like

Hi Alphi,

Just thought i would add this,my simple findings.
When i first got these RTLduino’s B&T.
When i run the simple example "blink "sketch on them from the Arduino IDE, the builtin led light never actually would light after uploading,BUT if i changed the code to BUILTIN_B or BUILTIN_R and uploaded the led would blink either blue or red whatever you specified.
What am saying is,it appears the default ‘green’ would not showup ? Not sure why this it.

Thank You

Hi Alphi,

Just thought i would mention. I did doa make all after replacing the original example_wlan_repeater.c file with the one you provided here.
When trying to compile with this replaced wlan_repeater.c file i get two errors:

example_wlan_repeater.c:112:17: error: 'example_wifi_status_thread' undeclared (first use in this function)
  if(xTaskCreate(example_wifi_status_thread, ((const char*)"example_wifi_status"), 1024, NULL, tskIDLE_PRIORITY + 2, NULL) != pdPASS)
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~
                 
                 /component/common/example/wlan_repeater/example_wlan_repeater.c:122:15: error: 'gpio_wlan_act' undeclared (first use in this function)
   gpio_write(&gpio_wlan_act, led);
               ^~~~~~~~~~~~~

Thanks for trying to help out here.

Hi brcisna
add GPIO initialize function , it’s compile without error

#include <platform_opts.h>
#include "FreeRTOS.h"
#include "task.h"
#include <platform/platform_stdlib.h>

#include "wifi_constants.h"
#include "wifi_structures.h"
#include "lwip_netconf.h"
#include "wifi_conf.h"
/* GPIO relate header file */
#include "gpio_api.h"
#include "PinNames.h"
#if CONFIG_EXAMPLE_WLAN_FAST_CONNECT
typedef int (*init_done_ptr)(void);
extern init_done_ptr p_wlan_init_done_callback;
extern int wlan_init_done_callback();
#endif
#if CONFIG_BRIDGE
extern void bridgeif_set_mac_init(char *bmac);
extern void bridgeif_add_port_ap_netif(void);
extern void bridgeif_add_port_sta_netif(void);
#endif

#if CONFIG_EXAMPLE_WLAN_REPEATER

#if CONFIG_LWIP_LAYER
extern struct netif xnetif[NET_IF_NUM]; 
#endif

#define GPIO_WLAN_ACT		PA_5
gpio_t  gpio_wlan_act;

static void example_wifi_status_thread(void *param)
{
	uint8_t led = 0;
	uint8_t i;
	for(i=0;i<10;i++) {
		gpio_write(&gpio_wlan_act, led);
		led^=1;
		vTaskDelay(1 * configTICK_RATE_HZ);

	}
	vTaskDelete(NULL);}
/**
 * @brief  Wi-Fi example for mode switch case: Mode switching between concurrent mode and STA and add to bridge.
 * @note  Process Flow:
 *              - Disable Wi-Fi
 *              - Enable Wi-Fi with concurrent (STA + AP) mode
 *              - Start AP
 *              - Check AP running
 *              - Connect to AP using STA mode
 */
static void example_wlan_repeater_thread(void *param)
{
	/* To avoid gcc warnings */
	( void ) param;

	// Wait for other task stable.
	vTaskDelay(4000);

	/*********************************************************************************
	*	1. Enable Wi-Fi with concurrent (STA + AP) mode
	*********************************************************************************/
	printf("\n\r[WLAN_REPEATER_EXAMPLE] Enable Wi-Fi with concurrent (STA + AP) mode\n");

	/*********************************************************************************
	*	1-1. Disable Wi-Fi
	*********************************************************************************/
	printf("\n\r[WLAN_REPEATER_EXAMPLE] Disable Wi-Fi\n");
	wifi_off();
	vTaskDelay(20);

	/*********************************************************************************
	*	1-2. Enable Wi-Fi with STA + AP mode
	*********************************************************************************/
	printf("\n\r[WLAN_REPEATER_EXAMPLE] Enable Wi-Fi with STA + AP mode\n");
	if(wifi_on(RTW_MODE_STA_AP) < 0){
		printf("\n\r[WLAN_REPEATER_EXAMPLE] ERROR: wifi_on failed\n");
		return;
	}

	uint8_t *mac = LwIP_GetMAC(&xnetif[0]);
	bridgeif_set_mac_init(mac);
	bridgeif_add_port_sta_netif();
	bridgeif_add_port_ap_netif();

	/*********************************************************************************
	*	1-3. Start AP
	*********************************************************************************/
	printf("\n\r[WLAN_REPEATER_EXAMPLE] Start AP\n");
	char *ssid = "AmebaRPT";
	char *password = "12345678";	// NULL for RTW_SECURITY_OPEN
	int channel = 6;

	if(wifi_start_ap(ssid, (password)?RTW_SECURITY_WPA2_AES_PSK:RTW_SECURITY_OPEN, password, strlen(ssid), (password)?strlen(password):0, channel) < 0) {
		printf("\n\r[WLAN_REPEATER_EXAMPLE] ERROR: wifi_start_ap failed\n");
		return;
	}

	/*********************************************************************************
	*	1-4. Check AP running
	*********************************************************************************/
	printf("\n\r[WLAN_REPEATER_EXAMPLE] Check AP running\n");
	int timeout = 20;
	while(1) {
		char essid[33];
		if(wext_get_ssid(WLAN1_NAME, (unsigned char *) essid) > 0) {
			if(strcmp((const char *) essid, (const char *)ssid) == 0) {
				printf("\n\r[WLAN_REPEATER_EXAMPLE] %s started\n", ssid);
				break;
			}
		}
		if(timeout == 0) {
			printf("\n\r[WLAN_REPEATER_EXAMPLE] ERROR: Start AP timeout\n");
			return;
		}
		vTaskDelay(1 * configTICK_RATE_HZ);
		timeout --;
	}

	/*********************************************************************************
	*	1-5. Connect to AP using STA mode and start DHCP client
	*********************************************************************************/
	printf("\n\r[WLAN_REPEATER_EXAMPLE] Connect to AP\n");
	if(p_wlan_init_done_callback)
		p_wlan_init_done_callback();
	if(xTaskCreate(example_wifi_status_thread, ((const char*)"example_wifi_status"), 1024, NULL, tskIDLE_PRIORITY + 2, NULL) != pdPASS)

	vTaskDelete(NULL);
}

void example_wlan_repeater(char* id){
	//initialize GPIO
	gpio_init(&gpio_wlan_act, GPIO_WLAN_ACT);
	gpio_dir(&gpio_wlan_act, PIN_OUTPUT);
	gpio_mode(&gpio_wlan_act, PullNone);

	gpio_write(&gpio_wlan_act, 0);


	if(xTaskCreate(example_wlan_repeater_thread, ((const char*)"example_wlan_repeater_thread"), 1024, NULL, tskIDLE_PRIORITY + 1, NULL) != pdPASS)
		printf("\n\r%s xTaskCreate failed\n", __FUNCTION__);
}

#endif /* CONFIG_EXAMPLE_WLAN_REPEATER */

Hi Alphi,

Thank You for this hard work!
It compiles fine.
Problem: rtlduino boots up , looks good, like before,in terminal and gets to were you hit enter key to start typing AT commands,It hangs here for about 10 seconds then freezes. Can never get the # to type in at commands.
It does this both the same in picocom Linux & Tera Term Windows. This has always worked without issue in both OS’s

Thanks again

Hi Brcisna,
You can provide a more detailed screenshot or message, because using wifi_repeater. theoretically, there are not implements AT command sets. This Behavior is confusing to me.

Hi Alphi,

I will attach a screenshot of what happens with this code, and also,(if I can a simple screen recording).
After I upload the code.
I reset the rtlduino.
In the terminal i still have to do:

  1. ATWS # scan for networks, this finds the drone’s SSID, Drone_XYZ
  2. ATW0=Drone_XYZ # drone SSID , add
    3.(do not need to do ATW1=password , as this is an open AP)
  3. ATWC # to connect the repeater to the drone Drone_XYZ , AP.
    Now in terminal I will see the repeater doing a successful connection to Drone_XYZ AP.

Hope this makes sense
The bottom line is when the repeater with this code boots up, I can not press enter to get to the # to enter the AT commands as it is locked up.
If you look at screenshot lower left the cursor is locked after blinking for a couple seconds.

See s