|
Forum Index : Microcontroller and PC projects : Bryans Car Club Record Project
| Author | Message | ||||
Bryan1![]() Guru Joined: 22/02/2006 Location: AustraliaPosts: 2184 |
G'day Guy's, Well it is time to start my own thread and I'm using several pico 3 computers all working together so the first thing to do was setup the snd.py and recv.py files which handles the wifi between the boards so here is the code For the PICO1 send.py >>> cat("send.py") import socket, os p = '/sd/1.jpg' n = os.stat(p)[6] s = socket.socket() s.connect(('192.168.4.16', 6001)) s.write('back.jpg,' + str(n) + '\n') f = open(p, 'rb') g = 0 while True: b = f.read(1024) if not b: break s.write(b) g = g + len(b) f.close() s.close() print('sent', g) >>> Now the recv.py >>> cat("recv.py") import socket s = socket.socket() s.bind(('0.0.0.0', 6001)) s.listen(1) c, a = s.accept() h = c.readline().decode().strip().split(',') n = int(h[1]) f = open('/sd/' + h[0], 'wb') g = 0 while g < n: b = c.read(1024) if not b: break f.write(b) g = g + len(b) f.close() c.close() s.close() print('got', g, 'of', n) Now for PICO2 the send.py >>> cat("send.py") import socket, os p = '/sd/cars/1.jpg' n = os.stat(p)[6] s = socket.socket() s.connect(('192.168.4.1', 6001)) s.write('1.jpg,' + str(n) + '\n') f = open(p, 'rb') g = 0 while True: b = f.read(1024) if not b: break s.write(b) g = g + len(b) f.close() s.close() print('sent', g) For the recv.py >>> cat("recv.py") import socket s = socket.socket() s.bind(('0.0.0.0', 6001)) s.listen(1) c, a = s.accept() h = c.readline().decode().strip().split(',') n = int(h[1]) f = open('/sd/' + h[0], 'wb') g = 0 while g < n: b = c.read(1024) if not b: break f.write(b) g = g + len(b) f.close() c.close() s.close() print('got', g, 'of', n) Now in our main.py >>> cat("main.py") import network ap = network.WLAN(network.AP_IF) ap.config(essid='pico1', password='pico1234') ap.active(True) synctime() for the pico2 >>> cat("main.py") import time time.sleep(6) wifi('pico1', 'pico1234') >>> This what I used to transfer a 440Kb file first via teraterm which was corrupt so setup my SDCard reader and putting the .py files on was easy. Now I did setup to the hotspot on my phone and left it going when we did the file transfer and the phone showed 0 data so the wifi just worked. Now the file was 1.jpg which is a jpg file I got off the club page which is a car photo, now got the error progressive jpg files not supported so although the picture didn't show transferring it did. Now after a day with Claude this what it had to say.... Sounds good. If it's useful for the writeup, the summary of where things landed: two Pico Computer 3 boards, one as AP and one as client, both coming up connected at boot with no intervention; TCP file transfer working both ways with a 441 KB JPEG as the test; and a SQLite-backed club system with member, cars and events pages on the HDMI GUI. The AP-mode finding might be the most useful thing for other people there — it fails consistently if you reconfigure the interfaces live, and works reliably when each board sets its role once at boot from main.py. That cost us most of a morning and isn't in the manual. Now what we came up for Day 1 club.zip Now doing a ls("/sd") >>> ls("/sd") <dir> 2024-12-06 10:22 Camera <dir> 2026-08-01 16:21 events <dir> 2025-09-01 16:02 Games <dir> 2026-08-01 12:55 members <dir> 2024-10-09 16:43 Music <dir> 2025-09-02 11:13 Programs <dir> 2025-08-26 09:06 System Volume Information 440973 2026-08-01 11:21 1.jpg 1948 2026-07-22 15:34 car_meet.py 2051 2026-07-22 10:07 car_meet.txt 11283 2026-07-25 11:14 carclub.py 45056 2026-08-01 16:50 club.db 23625 2026-08-01 16:50 club.py 5654 2026-08-01 17:20 club.zip 1688 2026-07-25 23:43 import_members.py 4748 2026-07-25 23:43 main.py 189 2026-07-23 15:18 members.csv 126 2026-07-23 15:18 members.csv.bak 8192 2026-08-01 16:31 members.db 7011 2026-08-01 14:39 members.py 2915 2026-08-01 04:35 menu.py 42 2026-08-01 13:26 roles.txt 18 2026-08-01 13:26 status.txt we can see the club.py file is at 23Kb and best of the club.db file is 45Kb and once I did that this what Claude said It's there — 23,625 bytes, timestamped 16:50. The 3456 figure was from the earlier listing before the transfer. Better still: club.db exists at 45,056 bytes, same timestamp. So you've already run it and SQLite created the database with all five tables. That's the whole thing working. Slight size difference from my 22,960 — probably line-ending conversion during the transfer, which is harmless for Python So now decision is do I work on this tomorrow or go on a car meet drive to Lamaroo to play golf and get closet to the hole. I haven't taken my 1996 C200 Mercedes out since I transferred it over to historic rego. Regards Bryan Edited 2026-08-01 18:01 by Bryan1 |
||||
| The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2026 |