Control a remote/wireless microcontroller from a computer connected to the same network. We will do this by using some python code on a computer to control the onboard LED of the NodeMCU microcontroller.
The NodeMCU has a wifi chip, so why don't we use it! There are many different libraries and strategies for sending data over wifi with the NodeMCU. However, one super versatile and friendly way to do this is by using the Open Sound Control (OSC) protocol. OSC was originally developed as an open source protocol for communication among audio hardware and software. However, it is also a great protocol for easy wifi communication among any piece of hardware or software that speaks OSC. An OSC packet is either a bundle or a message. Bundles are just groups of messages sent at one time. In this exercise we will just be sending a message. Each message has both an address and one or more pieces of data. The address allows both the client (sender) and the server (reciever) to identify the data and the address always starts with a "/" character. For example "/led", "/a/1", and "/a/2" are all addresses. The data can be an int, float, or string. If you want to read up on the full protocol, and additional features like timestamps and additional data types check out the full spec.
Another great thing about OSC is that there are lots of applications and libraries that implement the protocol. Some examples include: Ableton Live, Max, PureData, OpenFrameworks, Python, C++, Java, Arduino, Unity, etc; for a comprehensive list of software that can send and receive osc, look here. By learning how to send and receive OSC messages from/to our NodeMCU microcontroller, we effectively become capable of communicating between our physical computing inventions, and any of these powerful applications.
$ python -VYou can download the latest version here.
$ pip install python-oscIf you do not have pip installed (you can tell by typing 'pip' in the command line), then install it using these instructions.
$ python3 ./osc_client.py
The arduino library is written by the Center for New Music and Audio Technologies at UC Berkeley that wrote the osc protocol and has great documumentation. I would highly recommend checking it out, esspecially the sections on Receiving Data, Routing/Dispatching, and OSCBundles.