mirror of
https://github.com/sascha-hemi/pycom-documentation.git
synced 2026-03-21 10:05:56 +01:00
fixed minor example details
This commit is contained in:
@@ -5,7 +5,30 @@ aliases:
|
||||
- tutorials/all/https.md
|
||||
- chapter/tutorials/all/https
|
||||
---
|
||||
Using HTTPS adds Transport Layer Security (TLS) to your network traffic. The advantage is an encrypted connection between your device and the server.
|
||||
|
||||
## Basic example
|
||||
```python
|
||||
from network import WLAN #note that you can also use LTE
|
||||
import socket
|
||||
import ssl
|
||||
import time
|
||||
|
||||
wlan = WLAN()
|
||||
wlan.init(mode=WLAN.STA, ssid='your ssid', auth=(WLAN.WPA2, 'your password'))
|
||||
print("connecting", end='')
|
||||
while not wlan.isconnected():
|
||||
time.sleep(0.25)
|
||||
print(".", end='')
|
||||
|
||||
print("connected")
|
||||
print(wlan.ifconfig())
|
||||
s = socket.socket(usocket.AF_INET, usocket.SOCK_STREAM)
|
||||
ss = ssl.wrap_socket(s) #adds TLS
|
||||
ss.connect(socket.getaddrinfo('pycom.io', 443)[0][-1])
|
||||
rec = ss.recv(4096)
|
||||
print(rec)
|
||||
```
|
||||
Basic connection using `ssl.wrap_socket()`.
|
||||
|
||||
```python
|
||||
@@ -15,6 +38,7 @@ import ssl
|
||||
s = socket.socket()
|
||||
ss = ssl.wrap_socket(s)
|
||||
ss.connect(socket.getaddrinfo('www.google.com', 443)[0][-1])
|
||||
ss.se
|
||||
```
|
||||
|
||||
Below is an example using certificates with the blynk cloud.
|
||||
|
||||
Reference in New Issue
Block a user