[fly-iot Feifanwulian] (14): Restart the open source project Actorcloud project, and use docker-compose to start successfully, switch the MySQL database, and use flask deploy to create the database table

Preface


The original link of this article is:
https://blog.csdn.net/freewebsys/article/details/108971807
fly-iot column:
https://blog.csdn.net/freewebsys/category_12219758.html

No reproduction is allowed without the permission of the blogger.
The blogger's CSDN address is: https://blog.csdn.net/freewebsys
The blogger's Nuggets address is: https://juejin.cn/user/585379920479288
The blogger's Zhihu address is: https://www.zhihu. com/people/freewebsystem

Video demonstration address

https://www.bilibili.com/video/BV1Ze411q7fS/

[fly-iot] (2): Restart the open source project Actorcloud project, switch the MySQL database, use flask deploy defender, and initialize the database table

1. Regarding the actorcloud project, reorganize the open source project code


Original project: https://github.com/actorcloud/ActorCloud

The projects are all open source using the Apache protocol.
Previous projects were also open source under the Apache protocol.

ActorCloud is an IoT platform for low-power IoT networks that provides one-stop platform services for enterprises. On the basis of safety and reliability, ActorCloud provides devices with communication capabilities for multiple protocol access, as well as device data and message flow management functions.

The platform provides basic device management functions to connect and manage a large number of devices, and realizes device message communication and data collection persistence; it integrates rule engines and data visualization management, and flexibly opens management and control APIs with multiple permission levels. The upper layer can be quickly developed through the API Application to achieve multi-terminal access and remote control of equipment.

IoT Hub: establishes a reliable two-way connection channel for terminals to connect to the cloud, performs authentication, protocol parsing and message routing;
device management: terminal registration activation and life cycle management, providing continuous monitoring of status, faults and traffic;
data engine: High-speed persistence, real-time analysis, rule transaction processing and visual display of acquired terminal messages;
application enablement: providing terminal SDK, APP SDK, open and rich REST API interface, integrated message push interface.

project address:

Front-end project address:
https://gitee.com/fly-iot/fly-iot-frontend
Back-end project address:
https://gitee.com/fly-iot/fly-iot-backend-python
docker-compose project address :
https://gitee.com/fly-iot/docker-compose

2. Install the driver using pymysql==1.0.2


SQL connection corresponding to pymysql==1.0.2 :

mysql+pymysql://root:mysqliot@mysql-iot:3306/fly_iot
即可

3. To solve the SQL problem, switch to_char to date_format

sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError) (1305, 'FUNCTION fly_iot.to_char does not exist')
[SQL: SELECT to_char(device_count_hour.`countTime`, %(to_char_2)s) AS to_char_1, sum(device_count_hour.`deviceCount`) AS sum_1 
FROM device_count_hour 
WHERE device_count_hour.`tenantID` = %(tenantID_1)s AND device_count_hour.`countTime` > %(countTime_1)s GROUP BY to_char(device_count_hour.`countTime`, %(to_char_3)s) ORDER BY to_char(device_count_hour.`countTime`, %(to_char_4)s)]
[parameters: {
   
   'to_char_2': 'HH24:00', 'tenantID_1': 'PghAoyPJ9', 'countTime_1': datetime.datetime(2023, 12, 31, 16, 10, 37, 632378), 'to_char_3': 'HH24:00', 'to_char_4': 'HH24:00'}]

报错:FUNCTION .to_char does not exist(to_char与date_format)

4. Solve the problem of determining whether a table exists in the database


    # https://database.guide/5-ways-to-check-if-a-table-exists-in-mysql/#:~:text=Another%20way%20to%20check%20whether%20a%20table%20exists,TABLE_TYPE%20LIKE%20%27BASE%20TABLE%27%20AND%20TABLE_NAME%20%3D%20%27Artists%27%3B
    # SELECT * FROM `system_info` ;
    table_check_sql = """
    SHOW TABLE STATUS FROM fly_iot WHERE Name = 'system_info';
    """
    is_exist = db.engine.execute(
        text(table_check_sql).execution_options(autocommit=True)
    ).first()

Then replace non-standard fields:

db.String,  替换成 db.String(200),
db.Column(db.String) 替换成 db.Column(db.String(200))

db.Column(JSONB) 替换成 db.Column(db.JSON)

db.Column(JSONB, 替换成 db.Column(db.JSON,

5. PostgreSQL plug-in TimescaleDB


TimescaleDB is an open source PostgreSQL time series database extension. Based on the powerful capabilities of PostgreSQL, TimescaleDB can provide automatic partitioning across time and space and complete SQL support.
TimescaleDB not only supports full SQL like a traditional relational database, but is also scalable like a NoSQL database. It has the following advantages:
simple and easy to use

PostgreSQL natively supports all SQL interfaces (including secondary indexes, non-time-based aggregation, subqueries, JOIN, window functions)
without changing any clients and tools for connecting and using PostgreSQL.
Time-oriented functions, API functions and
powerful optimization Support for data retention strategies

Link: https://juejin.cn/post/7004641103320203301

3. Summary


Restart the open source project Actorcloud project and use docker-compose to start successfully.
Original project: https://github.com/actorcloud/ActorCloud
The entire project was not written by me. I just organized the information and then messed with the environment to get the project running.
Use docker-compose to run the relevant front-end, back-end, and database, but there is currently no MQTT service.
Continue to work hard, and the modified project code and deployment files have been put on gitee and open sourced.
I am the porter of this project, and everyone can study and research together. The projects are all open source using the Apache protocol.
Previous projects were also open source under the Apache protocol.

The original link of this article is:
https://blog.csdn.net/freewebsys/article/details/108971807

Insert image description here

Guess you like

Origin blog.csdn.net/freewebsys/article/details/135331039