Skip to content

Programmatic Scan

The programmatic_scan module demonstrates how to run a CLI command from your program and capture its output for program use.

Build it from project programmaticScanDemo.

Function Details

The following is an overview of the functions used in the programmatic_scan module.

static void processScanResults(
    const char *ssid,
    const uint8_t *bssid,
    uint8_t channel,
    int rssi,
    unsigned char security_suite,
    unsigned char encr_flags
) {...}

Print debug information to trouble log.

static void parseScanLine(const char *scanLine) {...}

Read formatted input from a string and send to processScanResults().

static bool writeData(
    struct output_stream *outStream,
    const char *data, size_t length
) {...}

Write the data to the scan line and then yield control to other threads using ltrx_thread_yield.

static bool writeNewline(struct output_stream *outStream) {...}

Determine if the scan is completed, and if so, write the new line. Then, yield control to other threads using ltrx_thread_yield.

static bool flushData(struct output_stream *outStream) {...}

Flush data from the output stream.

static bool outputClose(struct output_stream *outStream) {...}

Close the output stream.

static void programmaticScanThread(void *opaque) {...}

Use ltrx_ip_address_state() to see if the IP interface is up. If not, use ltrx_thread_sleep() to pause the thread for 1000 ms to allow time for WLAN0 to come up.

Use ltrx_input_stream_init_from_const_char() to construct input stream from const character, and when up, send "Starting scan." message to trouble log.

Use ltrx_cli_command_loop() to enter command line interface.

Closes the input stream with ltrx_input_stream_close() and pause the thread with ltrx_thread_sleep().