Introduction
In the previous post, we learned how to create an Arduino hub using the Simple Repository IO library.
Now it's time to make it talk with an server.
What are the problems I want to solve?
I want to create Arduino Hubs with actuators and sensors, but they must be controlled remotely.
This will (?) ease my mind that wants to create something.
What is the solution?
After creating an Arduino library, I must create a server to do the remote communication.
Weak points
- The server is intended to run on your LAN only
- You can do changes to make it work on the WEB
-
I'll create an NPM library to make it easier to call the commands without duplicating code over your servers' code.Packages created. - It relies on Multicast
- I don't know your LAN configuration, but if you're here I hope you know how to handle that
- Right?
Intended public
I expect you to have some knowledge regarding: TCP, UDP, IP ranges, and Typescript (not only C/C++)
Let's start
Library
In your Arduino IDE install the Simple Repository IO
Changing the wiring from previous post
What | Amount |
---|---|
Arduino* | 1 |
breadboard | 1 |
220 ohm resistor | 1 |
Led (built in) | 1 |
Led | 1 |
- I hope you have a WeMos D1 R1 compatible Arduino board or an Wi-Fi module compatible with
ESP8266WiFi
and know how to wire it
Pin D10 to resistor
Resistor to LED
LED to GND
Code
I created a tag so you can use the same version I used for this article.
-
Hub >> arduino code files
- It starts defining the components (see last article to better understanding)
- Then it MULTICASTS a message via UDP. Something like "I live, again"
- Wait for WiFi TCP messages with some command
-
Server >> typescript node server
- It starts two servers
- UDP server to add hubs to its list
- TCP server to act as an API
- each endpoint calls the Arduino
Results
When calling http://localhost:3000/Hub_A/write/led/true
When calling http://localhost:3000/Hub_A/write/led/false
When the pwm_led
is set to 0 (zero) and calling http://localhost:3000/write/Hub_A/pwm_led/100
Top comments (0)