Results 1 to 11 of 11

Thread: VB6 to RPi Pico W connection

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2022
    Posts
    4

    VB6 to RPi Pico W connection

    G'day all
    First time to post here, and looking for some clues in coding.
    I have an idea that I'd like to try and implement, but absolutely clueless on how to go about it.... The idea, in a nutshell, is to code a VB6 'master' program on a WIN10 machine to communicate to several Raspberry Pi Pico W's, through a WiFi access point (a remote connection point that's used because the main WiFi is out of range)
    See the rough graphic below for the LAN schematic...

    (Note though, there's no need for internet access... this is purely an internal network project, to/from PC and nodes)

    What I'm trying to do is connect to the remote nodes (a single node at any one time), send a command string from the VB6 app, say... send a request to node 3 of 'what is the output 1 state' and have that node respond with an 'on' or 'off' response. The LAN path will be WIN 10 machine to the Switch, to the Access Point to the node.
    I've done similar using MSComm VBX to a RPi4, all worked perfectly, but that was purely a wired LAN setup.
    My downfall is the WiFi part of the structure.

    As a run down on my skill level, I've been using VB on and off for a few years, but not very experienced in it - more a monkey-see, monkey-do type of coder. I can generally get the idea of how something works once I get a push in the right direction, but usually struggle to come up with a 'new' (to me!) concept - like this idea. Once I get the ball rolling, I can take it from there and develop a working program.
    I'm opting for VB6, because I'm most familiar with it, and don't need to go to the trouble of learning VB.net for a new project - I'm already needing to learn Python, so I don't want the extra hassle of VB.net on top of it.

    Does anyone have any experience or ideas that might get me on the track for VB6 to RPi Pico wireless comms that might fit the bill?
    Attached Images Attached Images  

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: VB6 to RPi Pico W connection

    There is a lot to work out that has nothing to do with programming languages or tools.

    First you need to decide how you will assign the remote devices unique IDs because IP addresses can change over time when using DHCP.

    Then you need some sort of discovery protocol since you can't rely on a proper implementation of NetBIOS to permit name resolution that way. Probably polling by sending out periodic UDP broadcasts that the remote reply to whenever these are seen.

    The reply could just be the unique ID, since you can get the IP address of the responding remote from he Winsock control. However you could also stuff that into the reply datagrams if you wanted to.

    Then, since UDP is an unreliable protocol subject to datagram loss and duplication, you could open TCP connections to replying remotes as a data path.

    Then you just need to write reliable code for handling the TCP connections and the data submitted over them to the PC. The TCP traffic could be about the same sort of thing you do now over serial ports.

  3. #3
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: VB6 to RPi Pico W connection

    I suppose you might have a range of unmanaged IP addresses on your hotspot and then configure the remote units manually to use distinct IP addresses from that range. Then you can manually maintain this list in the PC application.

    Such a fixed-IP approach can mean simpler programming since you don't need to deal with discovery, but might be clumsier to use in the field.

  4. #4
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,418

    Re: VB6 to RPi Pico W connection

    Quote Originally Posted by dilettante View Post
    I suppose you might have a range of unmanaged IP addresses on your hotspot and then configure the remote units manually to use distinct IP addresses from that range. Then you can manually maintain this list in the PC application.

    Such a fixed-IP approach can mean simpler programming since you don't need to deal with discovery, but might be clumsier to use in the field.
    Addition to this: In general, on a router/switch/computer (the device which actually is the DHCP-Server!) you can assign static IP's server-side, meaning the connecting RPi's are still in "DHCP"-Mode, but get assigned always the same IP from the Router. I've done this on my Home-Router for my iPad, iPhone, all my Laptops.
    My Laptops always get assigned the same IP-Address independent if connected by WiFi or wire

    This might be of interest:
    https://learn.microsoft.com/en-us/wi.../api/dhcpsapi/

    and in particualr:
    https://learn.microsoft.com/en-us/wi...msubnetclients
    https://learn.microsoft.com/en-us/wi...cp_client_info

    Bottom Line: With the DHCP-API's you can query the DHCP-Server, which RPi's are connected with which IP. Usually the unique ID dilettante is talking about is the MAC-Address of the remote device
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  5. #5

    Thread Starter
    New Member
    Join Date
    Sep 2022
    Posts
    4

    Re: VB6 to RPi Pico W connection

    All good suggestions, thanks for the pointers

    After further pondering, I'm toying with the idea of connecting each 'NEWly' installed node to the PC (probably via USB connection) and assigning a static IP to that address, which should eliminated the need for DHCP on the network. No problems there, that I can see.
    I'm not really sure how to tackle the SSID and connect to a SPECIFIC network... For my current situation, there's only one SSID in the area (the nearest neighbours are 250 mtrs away, so I don't have a problem with multiple WiFi networks in range), but, how can I connect to my SSID - if there was in fact more than one WiFi?

    Just to be clear, I don't have a RPi Pico at the moment... it's all academic right now to determine if it's a doable concept.

  6. #6
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: VB6 to RPi Pico W connection

    You might save some grief and look at ESP8266 or ESP32 instead of any "Pi" devices. For one thing they are probably easier to obtain at this point in time.

  7. #7
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,418

    Re: VB6 to RPi Pico W connection

    Quote Originally Posted by Foster660 View Post
    After further pondering, I'm toying with the idea of connecting each 'NEWly' installed node to the PC (probably via USB connection) and assigning a static IP to that address, which should eliminated the need for DHCP on the network. No problems there, that I can see.
    Don't.
    In your picture i see an ADSL-Modem/Router.
    At a guess: That device IS the DHCP-Server of your Network.
    Any RPi connecting to the Access Point WILL get registered at that Router.

    Some years ago i did have a small home network with just a switch and all static IP.
    It's not worth the hassle maintaining that thing

    EDIT: If you really, really want to go down the "manual" road (no DHCP-Server and whatnot)
    your best friend is the "arp"-command-line-tool
    https://learn.microsoft.com/en-us/wi...s-commands/arp

    Code:
    'in a CMD-Session, elevated to Administrator
    'Deletes the whole cache
    arp -d *
    
    'Read all connected devices and pipe into a file
    arp -a >>"c:\temp\arp.txt"
    btw: IIRC, there is an option on any Device to always connect to your Wifi and ignore any other Wifi's, so your neighbors WiFi shouldn't matter
    Last edited by Zvoni; Sep 29th, 2022 at 03:09 AM.
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  8. #8

    Thread Starter
    New Member
    Join Date
    Sep 2022
    Posts
    4

    Re: VB6 to RPi Pico W connection

    Thanks for the info, it's all much appreciated!

    Some years ago i did have a small home network with just a switch and all static IP.
    It's not worth the hassle maintaining that thing
    Yep, I agree... I've done the same thing myself in the past and it ends up being a nightmare. Now I just reserve the router and (now) the access point as static. Keep it simple!

    Anyway, I've ordered a Pico that's probably a week away before it lands in my mailbox. I'll have a fiddle and see what I can make happen. I'll keep you informed

  9. #9
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,418

    Re: VB6 to RPi Pico W connection

    To reiterate:
    Don't assign/configure the static IP on the end-device (your RPi), assign/config it on the Router!
    Yes, for that to be possible, the end-device has to be connected (in any way whatsoever) to your router ONCE!
    The moment the end-device becomes known to your Router, you can assign a static IP to it. After that it's just a Lease-Renew.

    Because, if you have to change your IP-Addresses of your end-devices later on, you just log into your router and change it there (kinda "all in one place")
    instead of climbing up trees to retrieve your end-devices, plug it into your Computer one after the other just to change the IP (or however it's done on that thing)

    I've done it that way in my skydiving-club.
    some 50 end-devices (phones, laptops, tablets) of some specific users are registered on the router with static ip-addresses.
    I could even access the router from "outside" (i was on vacation far away when i got a phonecall) and adjust stuff
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  10. #10
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,116

    Re: VB6 to RPi Pico W connection

    Quote Originally Posted by Zvoni View Post
    Some years ago i did have a small home network with just a switch and all static IP.
    It's not worth the hassle maintaining that thing
    I'll see your hassle and raise you x10.

    In the early 2000's, I worked for a fairly large organization that had about 5000-6000 workstations, 200+ servers, 400+ network printers, spread across 10 or so locations within a 100 mile radius. Everything was static IP's!

    Even worse, long before I started working there, when it came time to decide on what IP ranges would be used, rather than using 10.x.x.x, the network staff at the time decided to use a public /8 block for crazy, unknown reasons. This meant, of course, that if there was ever a need to connect to the "real owners" of IP addresses in this block, it wouldn't be possible from anywhere within the WAN. Thankfully, if I remember correctly, that block was mainly dedicated to Russia or China, and I never heard of any legit need to connect to them. After I had worked there for 5 years or so, DHCP was eventually implemented. Shortly after I left, there was a huge project to migrate everything to 10.x.x.x addressing.

    That's just the tip of the iceberg as far as how messed up things were there. It was one of those environments where the amount of chaos and mismanagement was overwhelming.

  11. #11

    Thread Starter
    New Member
    Join Date
    Sep 2022
    Posts
    4

    Re: VB6 to RPi Pico W connection

    G'day All,
    I've managed to get further into this idea, so as promised, here's the update...

    Seems to be a fairly bullet-proof(ish) concept with the only stumbling point at this stage is a little code crunching by the Pico when power is lost and repowered. It's impossible to catch any errors when the device has no power, so I can live with that

    So, the concept is this : The remote client (MicroPython code on a Pico W board) connects to WiFi and continually runs in a loop waiting for connection from the server LAN (VB coded, running on a Win10 PC). When the two are connected, the client waits for instructions, and in this trial - it loops back the data that was sent, to be displayed on the VB server text box.
    A simple comms concept, but proves it can be done.
    If the server disconnects, the client happily goes into a loop waiting for the next connection from the server. If the client disconnects, the server shows the status and will only connect again with a manual reconnection using a button.

    Right now, all the addresses are hard coded in, but for trials that's good enough for me.

    Conditional trapping was tricky for me (my first time coding in MicroPython, so I didn't really know what I was doing!), but I've got it to recover from lost communications, either from the server side or the client side.
    I've attached all the code that could be a good starting point if anyone else has the same sort of idea. It might help to get started and save a few grey hairs in the process!
    The Python code just needs your own SSID and Password, and it should be good to go...

    Thanks for everyone's help along the way... much appreciated
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width