Luigi Francesco Cerfeda
Published © GPL3+

Using Python and Arduino MKR1000 for Secure IoT

Getting started with Python and Arduino MKR1000 for secure IoT projects.

EasyFull instructions provided1 hour8,299
Using Python and Arduino MKR1000 for Secure IoT

Things used in this project

Story

Read more

Schematics

arduino_mkr1000_python_-_pinmap_64bsfgwRAj.png

Arduino mkr1000 python   pinmap 64bsfgwraj

Code

Code snippet #1

Python
pinMode(LED0, OUTPUT)
 
# loop forever
while True:
    digitalWrite(LED0, HIGH)  # turn the LED ON by setting the voltage HIGH
    sleep(1000)               # wait for a second
    digitalWrite(LED0, LOW)   # turn the LED OFF by setting the voltage LOW
    sleep(1000)               # wait for a second

Code snippet #2

Python
################################################################################
# Zerynth Secure Sockets
################################################################################
 
 
# import streams & socket
import streams
import socket
 
# import json parser, will be needed later
import json
 
# import the wifi interface
from wireless import wifi
 
# import the http module
import requests
 
# the wifi module needs a networking driver to be loaded
# in order to control the board hardware.
# FOR THIS EXAMPLE TO WORK, A NETWORK DRIVER MUST BE SELECTED BELOW
 
# uncomment the following line to use the CC3000 driver (Particle Core or CC3000 Wifi shields)
# from texas.cc3000 import cc3000 as wifi_driver
 
# uncomment the following line to use the BCM43362 driver (Particle Photon)
# from broadcom.bcm43362 import bcm43362 as wifi_driver
 
# uncomment the following line to use the WINC1500 driver (MKR1000)
from microchip.winc1500 import winc1500 as wifi_driver
 
 
streams.serial()
 
# init the wifi driver!
# The driver automatically registers itself to the wifi interface
# with the correct configuration for the selected board
wifi_driver.auto_init()
 
 
# use the wifi interface to link to the Access Point
# change network name, security and password as needed
print("Establishing Link...")
try:
    # FOR THIS EXAMPLE TO WORK, "Network-Name" AND "Wifi-Password" MUST BE SET
    # TO MATCH YOUR ACTUAL NETWORK CONFIGURATION
    wifi.link("Network-Name",wifi.WIFI_WPA2,"Wifi-Password")
except Exception as e:
    print("ooops, something wrong while linking :(", e)
    while True:
        sleep(1000)
 
# let's try to connect to https://www.howsmyssl.com/a/check to get some info
# on the SSL/TLS connection
 
        
for i in range(3):
    try:
        print("Trying to connect...")
        url="https://www.howsmyssl.com/a/check"
        # url resolution and http protocol handling are hidden inside the requests module
        user_agent = {"User-Agent": "curl/7.53.1", "Accept": "*/*" }
        response = requests.get(url,headers=user_agent)
        # if we get here, there has been no exception, exit the loop
        break
    except Exception as e:
        print(e)
 
 
try:
    # check status and print the result
    if response.status==200:
        print("Success!!")
        print("-------------")
        # it's time to parse the json response
        js = json.loads(response.content)
        # super easy!
        for k,v in js.items():
            print(k,v)
        print("-------------")
except Exception as e:
    print("ooops, something very wrong! :(",e)

Credits

Luigi Francesco Cerfeda

Luigi Francesco Cerfeda

2 projects • 57 followers
Yet another Tony Stark wannabe
Contact

Comments