Using Python and Arduino MKR1000 for Secure IoT

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

Using Python and Arduino MKR1000 for Secure IoT

Things used in this project

Hardware components

Arduino MKR1000
Arduino MKR1000
× 1

Software apps and online services

Zerynth Studio
Zerynth Studio

Story

Schematics

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)


About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top