Back

Unihiker K10 lesson 5

Introduction:
In this lesson, you will build a basic IoT (Internet of Things) application using the UNIHIKER K10. You’ll connect the device to a Wi-Fi network, read sensor values, and send the data to a cloud or local server using HTTP. This transforms your K10 from a standalone dashboard into a connected data logger, capable of contributing to smart monitoring systems.

What You’ll Learn:

  • How to connect the UNIHIKER K10 to Wi-Fi

  • How to collect sensor data in real-time

  • How to send JSON data to a web server using HTTP POST

  • How to troubleshoot connectivity issues


🔧 Step 1: Connect to Wi-Fi

Start by connecting to your Wi-Fi network. Replace "YourSSID" and "YourPassword" with your actual credentials.

python
import network import time wlan = network.WLAN(network.STA_IF) wlan.active(True) wlan.connect("YourSSID", "YourPassword") while not wlan.isconnected(): time.sleep(1) print("Wi-Fi Connected!") print(wlan.ifconfig())

Once connected, the K10 prints its IP address and becomes ready to send or receive data.


🌡️ Step 2: Read Sensor Data

Now you can collect real-time data from onboard sensors.

python
from pinpong.board import Board from pinpong.libs.unihiker import TempHumSensor, LightSensor Board().begin() temp_humi = TempHumSensor() light = LightSensor() temp, humi = temp_humi.read() light_val = light.read()

🌐 Step 3: Send Data Over HTTP

Use the urequests library to send your readings to a cloud server or local endpoint.

python
import urequests data = { "temperature": temp, "humidity": humi, "light": light_val } response = urequests.post("http://yourserver.com/api", json=data) print(response.text)

Make sure your server supports HTTP POST and accepts JSON. You can use services like ThingSpeak, Node-RED, or your own Flask/MQTT server.

Leave A Reply