Page 1 of 1

Could someone implement a C function for connecing to WLAN with Python?

Posted: Sat Oct 13, 2018 9:50 am
by heikki.hietala
Hi,

I was thinking that it would be cool if someone could work on the C function available for connecting to a WPA2 Enterprise network?

i can do a regular WLAN connection over Python, no problem, or, use C as my language to connect to Eduroam, but getting connected to Eduroam over Python would suit my purposes much better. I haven't found a Python way of doing this, but a C function made available for Python would work really well.

Any takers? I am not too well versed in stuff like this and could use a hand in this.

Cheers,

-h.

Re: Could someone implement a C function for connecing to WLAN with Python?

Posted: Sun Oct 14, 2018 3:03 am
by jickster
Your request is too vague.




Sent from my iPhone using Tapatalk Pro

Re: Could someone implement a C function for connecing to WLAN with Python?

Posted: Sun Oct 14, 2018 8:45 am
by heikki.hietala
Okay, sorry - I was looking for someone to work with over this, but I will explain.

The following code connects ESP32 using the Arduino IDE. I would love to have the code available as a function in Python. I am such a beginner in this that I thought someone probably has done this already.


+++++++++++++++

#include "esp_wpa2.h"
#include <WiFi.h>

const char* ssid = "MY_SSID"; // your ssid
#define EAP_ID "MY_EAP_ID"
#define EAP_USERNAME "MY_EAP_USERNAME"
#define EAP_PASSWORD "MY_EAP_PASSWD"

void setup() {
Serial.begin(115200);
delay(10);

Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);

// WPA2 enterprise magic starts here
WiFi.disconnect(true);
esp_wifi_sta_wpa2_ent_set_identity((uint8_t *)EAP_ID, strlen(EAP_ID));
esp_wifi_sta_wpa2_ent_set_username((uint8_t *)EAP_USERNAME, strlen(EAP_USERNAME));
esp_wifi_sta_wpa2_ent_set_password((uint8_t *)EAP_PASSWORD, strlen(EAP_PASSWORD));
esp_wpa2_config_t config = WPA2_CONFIG_INIT_DEFAULT();
esp_wifi_sta_wpa2_ent_enable(&config);

// WPA2 enterprise magic ends here


WiFi.begin(ssid);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}

Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());

}

++++++++++++++++

So, how does one turn this into a Python module?

Many thanks in advance!

Re: Could someone implement a C function for connecing to WLAN with Python?

Posted: Mon Oct 15, 2018 10:43 pm
by jickster
If you just need to wrap this existing code and make it available in .py, there's plenty of examples on how to do that.

Re: Could someone implement a C function for connecing to WLAN with Python?

Posted: Tue Oct 16, 2018 6:51 am
by pythoncoder
@heikki.hietala What is the aim in rewriting working Python code in C? Performance is almost certainly limited by the network.

So I assume your aim is security. I don't think there is a solution to an attacker with unrestricted access to the hardware. A very limited degree of obfuscation may be achieved by freezing the Python bytecode. This would flummox the average twelve year old; but not a clever one. Even C code will have the credentials stored in plaintext unless you go to lengths to avoid it.

The issue of hiding Python source is a FAQ and a forum search will be informative.

Re: Could someone implement a C function for connecing to WLAN with Python?

Posted: Tue Oct 16, 2018 7:01 am
by heikki.hietala
Thanks for the reply. My point is that I have not been able to find a working implementation of Python in connecting to WPA 2 Enterprise network, but this C code does that.

My apologies if this is a null query, but I am stumbling on this now.

How to connect to a WPA2 Enterprise network?

Posted: Tue Oct 16, 2018 1:00 pm
by pythoncoder
Sorry, I misunderstood. I assumed you'd translated working Python code into C. I think a first step is to ask if anyone has managed to do this in MicroPython. I do wonder whether many people here are in a position to test this.

The alternative is to follow the approach suggested by @jickster.

Re: Could someone implement a C function for connecing to WLAN with Python?

Posted: Tue Oct 23, 2018 4:19 am
by heikki.hietala
Thanks Peter, I am now checking out the wrapping method and if I crack it, I'll post in github. It seems doable even for a n00b like me.

Re: Could someone implement a C function for connecing to WLAN with Python?

Posted: Mon Jun 20, 2022 5:53 pm
by MATTYGILO
Has this been achieved yet???

Re: Could someone implement a C function for connecing to WLAN with Python?

Posted: Mon Jun 20, 2022 6:41 pm
by heikki.hietala
Not by me in any case, I resorted to another network hotspot.