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

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
heikki.hietala
Posts: 10
Joined: Thu Oct 11, 2018 4:52 pm

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

Post by heikki.hietala » Sat Oct 13, 2018 9:50 am

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.

jickster
Posts: 546
Joined: Thu Sep 07, 2017 8:57 pm

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

Post by jickster » Sun Oct 14, 2018 3:03 am

Your request is too vague.




Sent from my iPhone using Tapatalk Pro

heikki.hietala
Posts: 10
Joined: Thu Oct 11, 2018 4:52 pm

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

Post by heikki.hietala » Sun Oct 14, 2018 8:45 am

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!

jickster
Posts: 546
Joined: Thu Sep 07, 2017 8:57 pm

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

Post by jickster » Mon Oct 15, 2018 10:43 pm

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.

User avatar
pythoncoder
Posts: 3126
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

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

Post by pythoncoder » Tue Oct 16, 2018 6:51 am

@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.
Peter Hinch

heikki.hietala
Posts: 10
Joined: Thu Oct 11, 2018 4:52 pm

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

Post by heikki.hietala » Tue Oct 16, 2018 7:01 am

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.

User avatar
pythoncoder
Posts: 3126
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

How to connect to a WPA2 Enterprise network?

Post by pythoncoder » Tue Oct 16, 2018 1:00 pm

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.
Peter Hinch

heikki.hietala
Posts: 10
Joined: Thu Oct 11, 2018 4:52 pm

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

Post by heikki.hietala » Tue Oct 23, 2018 4:19 am

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.

Post Reply