Skip to content

Instantly share code, notes, and snippets.

View RajivCodeLab's full-sized avatar
🏠
Working from home

Rajiv Lochan Sharma RajivCodeLab

🏠
Working from home
View GitHub Profile
@RajivCodeLab
RajivCodeLab / MQTT_PICO_W.py
Created May 14, 2024 06:14
Raspberry Pi Pico W MicroPython MQTT Tutorial | Control LED using MQTT Node Red
import network
from umqtt.simple import MQTTClient
import time
import machine
MQTT_BROKER="YOUR_SYSTEM_IP"
MQTT_PORT = 1883
MQTT_CLIENT_ID="pico_client"
led_green = machine.Pin(0, machine.Pin.OUT)
@RajivCodeLab
RajivCodeLab / index.html
Created April 27, 2024 15:04
How to Run React JS on Raspberry Pi Pico W and Control Two LEDs
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Raspberry Pi Pico - React.js</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
@RajivCodeLab
RajivCodeLab / docker-compose.yml
Created April 18, 2024 17:52
Setup Home Assistant on Docker Windows (2024)
version: "3.9"
services:
homeassistant:
container_name: homeassistant
image: ghcr.io/home-assistant/home-assistant:stable
volumes:
- 'C:\docker\homeassistant:/config'
environment:
- IN=Asia/Calcutta # You can find your time zone here - https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
ports:
@RajivCodeLab
RajivCodeLab / index.html
Created April 17, 2024 08:20
WebSocket on Raspberry Pi Pico W using (MicroDot)
<!DOCTYPE html>
<html>
<head>
<title>Live Temperature Dashboard</title>
<meta charset="UTF-8">
<!-- Include Chart.js library -->
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<style>
@import url(https://fonts.googleapis.com/css?family=Open+Sans:700,300);
@RajivCodeLab
RajivCodeLab / LED_CONTROL_REST_API.py
Created April 10, 2024 04:37
REST API for Raspberry Pi Pico
from phew import server, connect_to_wifi
import machine
import json
ip = connect_to_wifi("YOUR_SSID", "YOUR_PASSWORD")
led_green = machine.Pin(0, machine.Pin.OUT)
led_red = machine.Pin(1, machine.Pin.OUT)
print("connected to IP ", ip)
@RajivCodeLab
RajivCodeLab / remote_controlled_led.py
Created April 6, 2024 10:15
To control the LED remotely from anywhere in the world using Raspberry Pi Pico W and DWEET.IO
import network
import sys
import time
import requests
import json
from machine import Pin
wlan = network.WLAN(network.STA_IF)
led = Pin(0, Pin.OUT)
@RajivCodeLab
RajivCodeLab / ip_scanner.py
Created April 4, 2024 13:06
IP Scanner (Used to find IP address of Raspberry Pi)
import tkinter as tk
from tkinter import messagebox
from scapy.all import ARP, Ether, srp
def get_connected_devices():
arp_request = Ether(dst="ff:ff:ff:ff:ff:ff") / ARP(pdst="192.168.1.0/24")
result = srp(arp_request, timeout=3, verbose=False)[0]
connected_devices = [{'ip': received.psrc, 'mac': received.hwsrc, 'hostname': received.getlayer(ARP).psrc} for sent, received in result]
@RajivCodeLab
RajivCodeLab / csv_read_write_temperature.py
Last active April 1, 2024 13:29
Reading and Writing CSV Files with Raspberry Pi Pico and MicroPython
import machine
import time
import os
# Function to read temperature sensor
def read_temperature():
adc = machine.ADC(4) # Use ADC pin GP4
conversion_factor = 3.3 / (65535) # ADC conversion factor
sensor_value = adc.read_u16() * conversion_factor
temperature = 27 - (sensor_value - 0.706) / 0.001721 # Convert sensor value to temperature (formula may vary)
@RajivCodeLab
RajivCodeLab / index.html
Created March 31, 2024 09:32
Build Your Own Web Server on Raspberry Pi Pico W and Phew
<!doctype html>
<html lang="en">
<head>
<title>Raspberry Pi Pico Web Server</title>
<!-- Required meta tags -->
<meta charset="utf-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no"
/>