element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Industrial Automation
  • Technologies
  • More
Industrial Automation
Blog Connect to AVNET iotconnect.io with Python IoTConnectSDK and BLE - part 2: WiFi Provisioning
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Industrial Automation to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Jan Cumps
  • Date Created: 9 May 2021 8:44 AM Date Created
  • Views 682 views
  • Likes 4 likes
  • Comments 0 comments
  • provision
  • wifi
  • service
Related
Recommended

Connect to AVNET iotconnect.io with Python IoTConnectSDK and BLE - part 2: WiFi Provisioning

Jan Cumps
Jan Cumps
9 May 2021

AVNET's iotconnect.io cloud platform is an online service that you can use to send data to, and then show it on a dashboard. In this blog series I'm learning the Python SDK and integrating BLE devices.

In this post: the mechanism to enter your credentials and configure WiFi without keyboard or wired network.

image

The technique in this post can be used on other Linux devices (Pi, BB, ...)

 

USB Memory Stick as WiFi configurator

 

The SmartEdge is a headless Linux device. How do you connect it to your WiFi router?

I've seen several options used by WiFi devices.

  • The out-of-box example for the Avnet SmartEdge acts as a WiFi access point. You can configure it to become a client for your network via an App on your phone.
  • For a Raspberry Pi out-of-box, you either hard wire it to the network and set WiFi over an SSH session, or you temporarily connect a keyboard and screen.
  • Others have a WPS button,
  • etc ..

 

The Avnet example for the SmartEdge uses a neat mechanism. A USB memory stick that you prepare with your connect info.

The box runs a Python script as a service that waits for you to plug in a USB.

If it detects a stick, the script mounts it, then it looks for a file named OnSemiConfig.txt.

It then takes the config found on the stick, configures the WiFi (and other things in the case of the example I'm reviewing).

Then it restarts the box.

 

        if(os.path.exists('/dev/sda1') == True):
            os.system("mount /dev/sda1 /mnt")
            if(os.path.exists('/mnt/OnSemiConfig.txt') == True):
                # ...
                # Usb stick inserted with onsemi configuration file
                # start processing the configuration
                config = configparser.ConfigParser()
                config.read('/mnt/OnSemiConfig.txt')
                my_config_parser_dict = {s:dict(config.items(s)) for s in config.sections()}
                # ...
                f = open('/etc/wpa_supplicant/wpa_supplicant.default', 'r')
                os.system('rm /etc/wpa_supplicant/wpa_supplicant.conf')
                f1 = open('/etc/wpa_supplicant/wpa_supplicant.conf', 'w')
                f1.write(f.read())
                f.close()
                f1.write('\n')
                f1.write("network={\n    ssid=\"%s\"\n    psk=\"%s\"\n}\n" % (my_config_parser_dict['onsemiconfiguration']['wifissid'] , my_config_parser_dict['onsemiconfiguration']['wifipsk']))
                f1.close()
                # ...
                # wait for usb removal
                os.system('/opt/avnet-iot/iotservices/wifi_client')
            else:
                # ...
            while(os.path.exists('/dev/sda1') == True):
                time.sleep(2)

            os.system('reboot')

 

Here is the WiFi related content of the config file on the stick.

 

[onsemiconfiguration]
wifissid=<your ssid>
wifipsk=<your password>

 

Running as a service

 

There's a shell script in the IoTConnect folder /opt/avnet-iot/iotservices, named usbwatcher.

 

#!/bin/bash
if [[ $EUID -ne 0 ]]; then
  echo "This script must be run as root"
  exit 1
fi
# ...
python -u /home/avnet/USBWatcher.py

 

And a service wrapper in /etc/systemd/system, named usbwatcher.service.

 

[Unit]
Description=UsbWatcher OnSemiConfiguration
StartLimitIntervalSec=0

[Service]
ExecStart=/bin/bash /opt/avnet-iot/iotservices/usbwatcher
Restart=always
RestartSec=10

[Install]
WantedBy=default.target

 

This takes care that you can start and stop the service, enable it at startup, ...

Here is a good explanation of this. And here is one that digs deeper in the subject.

 

 

The Python SDK with On Semiconductor RSL10 BLE article seriesIndustry
part 1: overview and goal
part 2: WiFi Provisioning
part 3: Adding a Module (RSL10)
part 4: Talk BLE to the On Semi RSL10 Sensor Kit
part 5: A Cloud User Experience Example
part 6: Register as a Gateway Device
part 7: Register a Gateway and Client Devices
The NODE-Red SDK article seriesIndustry
part 1: overview and goal
register a Thing and connect to IoTConnect.io cloud
part 2: create an account and log on to the portal
part 3: set up the thing and its interface in the cloud
part 4: set up Node-RED and first exchange
interact with IoTConnect.io cloud
part 5: online dashboard
part 6: rules and alerts
part 7: messages and commands from the cloud
safer connections with certificates
part 8a: safer connect with Self Signed Certificates
part 8b: safer connect with CA certificatesY
commercial and industrial scale: outsource certificate generation and programming to subcontractors and suppliers
part 9a: Outsource Certificate Signing in IIoT Supply ChainY
part 9b: IIoT supply chain and Certificates - Create Ca Root certificate, Load to IoTConnect Cloud and ValidateY
part 9c: IIoT supply chain and Certificates - Create an Intermediate CA Certificate for your SubcontractorY
part 9d: IIoT supply chain and Certificates - Subcontractor Generates a Thing Certificate for Your DeviceY
part 9e: IIoT supply chain and Certificates - Test!Y
commercial and industrial scale: Trusted Platform Module (TPM) Authentication
part 10: Trusted Platform Module (TPM) SecurityY
Infineon SLx9670 Trusted Platform Module (TPM) for IoT SecurityY
The Automate Device Provisioning and Cloud Configuration article seriesIndustry
Automatic Provisioning with REST APIY
  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube