frame

Accessing WIFI lower level APIs

GunnerMBTGunnerMBT Member
edited December 2017 in Libraries & Drivers
Hey, I came across this wifi-sniff module written in C and I'd like to re-write it in Python. The issue is, as I've understood, I can only use the APIs exposed by the Zerynth framework, and I'd have to go a little "deeper". How should I go about doing this? I know I can call C code from Python, but I'd like it to be a native implementation. 

Thanks!

Edit: the module is https://www.hackster.io/rayburne/esp8266-mini-sniff-f6b93a
Tagged:
Tagged:

Comments

  • Hi GunnerMBT,

    I check the example code you posted and all Low-Level APIs used are available in Zerynth.
    If you want to know more about available APIs, you can check the "symdef" field of the VM file inside the zerynth2/vms/your_device/your_device_id/your_vm_file (you have to create the VM first).

    In "symdef" field you can find the available APIs with this format SYM(API); all these functions are callable in C language and you can develop a Python wrapper to use them.

    An implementation example is the Wi-Fi library for ESP8266 (you can find it inside zerynth2/dist/r2.0.10/libs/official/espressif/esp8266wifi folder):
     - in the esp8266wifi.py you can define a @native_c method that calls a custom c function (you have to indicate also the source file);
     - in the csrc/wifi_ifc.c file you can find the body of the custom c function with the sequence of the Low-Level APIs used.

    Hope this can help you, and feel free to ask more help :)
    Matteo Cipriani
    Zerynth Support Team
  • Hey, thanks for your answer! I checked both esp8266wifi.py and wifi_ifc.c and only a handful of the wifi functions are defined. Are you saying I need to implement the rest of them? I thought they'd be already implemented :P. Should be fun nonetheless!
  • Hi GunnerMBT,

    We port and implement a subset of Wi-Fi functionalities that permit to cover the most use case and to be compatible with our generic wifi.py library (under stdlib/wireless folder) that (according to the Wi-Fi driver chosen) creates an abstraction layer to render the custom script independent from the Wi-Fi hardware.

    Said that, you can modify/upgrade the library as you want and we will happy to support you during your custom implementation; besides the Wi-Fi sniff, which functions, in particular, do you need?

    When you finished, tested, and documented your new custom Wi-Fi functions, we will also happy to publish the modified library to make available this new features for the whole Zerynth Community.

    Feel free to post me :)
    Matteo Cipriani
    Zerynth Support Team
  • Hey

    What I aim to do is, basically, detect devices and get an approximate distance without the need to be connected to the same AP. Sort of a "if device X is close, do something".
    I'm not sure what you mean, the specific wifi APIs I'll need? Or completely besides Wi-Fi sniff thingy? 
    I'd need anything that enables me to enter promiscuous mode and scan the network, I'll need to take a closer look. If the latter, well, no idea yet. I want to build a tiny home-security system, despite being somewhat of a cliché project, so to speak, it seems like a good starting point in IoT!

    Thanks!
  • Great IoT project! B)

    Regarding the APIs, from their SDK every "Sniffer Related APIs" are exposed in Zerynth.
    I can send you a more readable list of all ESP8266 APIs available in Zerynth and if you need other APIs not supported yet, you can write me sending those missing; if it's possible, we will expose them ASAP.

    Keep me posted :)
    Matteo Cipriani
    Zerynth Support Team
  • GunnerMBTGunnerMBT Member
    edited December 2017
    That would certainly be helpful, thanks! I couldn't seem to find all the APIs, maybe I'm looking in the wrong place. 

    Edit: Oh, you meant exposed by calling them in C! Right!
    Shouldn't calling, for instance, "wifi_set_promiscuous_rx_cb" in Python throw an error? Is it somehow trying to call the C definition of said function? That's what confused me at first, I was trying to use the mentioned APIs but neither an error was thrown or anything seemed to happen!
  • Hi GunnerMBT,

    Native ESP8266 SDK APIs, are callable only in C language.
    To better understand, you can post/send me your code and I'll give you support if you need. ;)
    Matteo Cipriani
    Zerynth Support Team
Sign In or Register to comment.

ZERYNTH Community

@ 2016 Zerynth.com, all rights reserved.