Day: December 10, 2024

  • SQL – notes

    create user

    CREATE USER '<username>'@'<connect from hostname>' IDENTIFIED BY '<password>';

    grant access

    # basic syntax
    CREATE USER '<username>'@'<connect from hostname>' IDENTIFIED BY '<password>';
    
    # as close to root without being root
    # probably shouldn't be giving any user this much access
    GRANT CREATE, ALTER, DROP, INSERT, UPDATE, DELETE, SELECT, REFERENCES, RELOAD on *.* TO '<username>'@'<connect from hostname>' WITH GRANT OPTION;

    database

    create database <databasename>;
    
    show databases;

    Inserting data

    # INSERT INTO Syntax
    # It is possible to write the INSERT INTO statement in two ways:
    # 1. Specify both the column names and the values to be inserted:
    
    INSERT INTO table_name (column1, column2, column3, ...)
    VALUES (value1, value2, value3, ...);
    
    # 2. If you are adding values for all the columns of the table, you do not need to specify the column names in the SQL query. However, make sure the order of the values is in the same order as the columns in the table. Here, the # INSERT INTO syntax would be as follows:
    
    INSERT INTO table_name
    VALUES (value1, value2, value3, ...);
  • $40 Kasa HS300 Smart Power Strip

    $40 Kasa HS300 Smart Power Strip

    I impulse-bought 2 of these because it seemed like exactly what I needed for a couple projects. 6 individually controlled power outlets, and three always on USB ports. Each port monitors voltage and amps. And I even found a Python library that controls it and all the other Kasa smart devices I own. 😍

    And look here. An official MySQL Python Connector.

    So, this is a start.

    # commented out code is example code...  for now
    import asyncio
    from kasa import Discover
    
    async def main():
        # dev = await Discover.discover_single("127.0.0.1",username="un@example.com",password="pw")
        # me no think me need login
        dev = await Discover.discover_single("192.168.1.230")
        
        # await dev.turn_on()
        # await dev.update()
        # me just want Info for now
        devInfo = dev.hw_info 
        print(type(devInfo))
        print(devInfo)
    
    if __name__ == "__main__":
        asyncio.run(main())

    which gives me this

    <class 'dict'>
    {'sw_ver': '1.0.12 Build 220121 Rel.175814', 'hw_ver': '2.0', 'mac': 'B0:19:21:DF:80:D0', 'mic_type': 'IOT.SMARTPLUGSWITCH', 'hwId': '955F433CBA24823A248A59AA64571A73', 'oemId': '32BD0B21AA9BF8E84737D1DB1C66E883'}

    I could probably use this command to populate the device table with ease.