Advertisement
chillichump

Beginners Guide to Automation Episode 17

Oct 30th, 2020 (edited)
3,307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.08 KB | None | 0 0
  1. /*
  2. https://youtu.be/3Ic7CZZ0a_U
  3. ChilliChumps Beginners Guide to Automation, Episode 17
  4.  
  5.  Log in to your Raspberry Pi server with PuTTY, and run the following commands in the Shell:
  6. - update: 5 nov 2020: It is possible that Apache webserver is not installed, I have added code to ensure this is installed.
  7. - update: 6 nov 2020: added new command if you are having permissions issues writing to the SQLite database
  8. */
  9.  
  10. //Start  of the shell commands
  11.  
  12. sudo apt-get update
  13. sudo apt-get upgrade
  14.  
  15. sudo apt-get install apache2
  16. sudo systemctl enable apache2
  17. sudo apt install php libapache2-mod-php
  18. sudo apt-get install php-sqlite3
  19. sudo systemctl start apache2
  20.  
  21. sudo apt-get install sqlite3
  22.  
  23. sudo apt install php-mbstring
  24. sudo systemctl stop apache2
  25. sudo systemctl start apache2
  26. sudo mkdir /databases
  27. sudo chmod +777 /databases
  28.  
  29. cd /var/www/html
  30. sudo mkdir database
  31. cd database
  32. sudo wget https://bitbucket.org/phpliteadmin/public/downloads/phpLiteAdmin_v1-9-8-2.zip
  33. sudo unzip phpLiteAdmin_v1-9-8-2.zip
  34. sudo rm phpLiteAdmin_v1-9-8-2.zip
  35. sudo cp phpliteadmin.config.sample.php phpliteadmin.config.php
  36. sudo nano phpliteadmin.config.php
  37.  
  38. // ---Make changes to the config file as per the video---
  39.  
  40. // End of the shell commands
  41.  
  42.  
  43. - URL for phpliteadmin: http://<rpi server ip>/database/phpliteadmin.php
  44.  
  45. - SQL for creating "IOTSensors" table:
  46.  
  47. CREATE TABLE "IOTSensors" ( ID INTEGER PRIMARY KEY, deviceName TEXT,'sensor' TEXT,'reading' INT ,'timestamp' DATETIME)
  48.  
  49.  
  50. --- To ensure the permissions for the database you created is correct, use the below command in the Shell:
  51.  
  52. sudo chmod -R +777 /databases
  53.  
  54. --- NODE-RED:
  55.  
  56. - Function code for pushing data into your database:
  57. // start of code
  58.  
  59. var sqliteTimeStamp = Math.round(Date.now() / 1000); //converting to seconds instead of milliseconds epoch
  60. var theDevice = "growtent";
  61. var theSensor = "t";
  62.  
  63. var theSQL = "INSERT INTO IOTSensors (timestamp, deviceName, sensor, reading) VALUES "
  64. theSQL = theSQL + "('" + sqliteTimeStamp + "', '" +  theDevice +"', '" + theSensor + "', " + msg.payload + ");";
  65. msg.topic = theSQL;
  66.  
  67. // end of code
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement