This is an implementation of a Smart LED, which uses a Raspberry Pi3B+ to add "smartness" to the LED.
- Raspberry Pi 3B+
- 1 LED, optional Resistor, connected in series with the LED
- Remote Switch On / Off LED
- Scheduled Turn On
- Show past usage statistics
SSH to the Raspberry Pi, and navigate to ~/rest-server/iot-smart-led
If running for the first time, run pip install -r requirements.txt
from the root folder
Install mysql DB by running sudo apt install mysql
To control which pin the LED is connected to, set the environment variable to the correct number with export LED_PIN=<pin number>
, and then start the server. The default is pin 40
Setup the MYSQL DB by running the commands specified in "dbcommands.txt"
The Angular Server needs the IP address of the Pi to run properly.
Modify the IP address to appropriate values in both the environment.ts
and environment.prod.ts
files under the src/environments
folder.
Run ./start.sh
from inside the "python" folder to start the REST server. It starts on port 5000
Navigate the the angular/smart-led
folder, and run npm start
. The Angular Server is accessible from port 4200
The UI for the application is available by navigating to the http://<IP addresss>:4200
.
Ensure that the DB is setup properly. See dbcommands.txt for reference.
Uncomment the Flask code in DB dbconn.py.
Run the test flask server through the command FLASK_APP=dbconn.py python -m flask run
Make the API calls through POSTMAN or Curl:
- curl http://localhost:5000/ - Get LEDs
- curl http://localhost:5000/on/0 - Switch On LED
- curl http://localhost:5000/off/0 - Switch Off LED
- curl http://localhost:5000/stats/0 - Get LED stats