Commit 6fc94101 by mohammed.shibili

receiver first commit

parents
# Default ignored files
/shelf/
/workspace.xml
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="PyPep8NamingInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
<option name="ignoredErrors">
<list>
<option value="N801" />
</list>
</option>
</inspection_tool>
</profile>
</component>
\ No newline at end of file
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (mqttReciver)" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/mqttReciver.iml" filepath="$PROJECT_DIR$/.idea/mqttReciver.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
from scripts.serviece.reciever import on_message, on_connect
on_connect()
on_message()
File added
import json
import sqlite3
import paho.mqtt.client as mqtt
def on_connect(client, userdata, flags, rc):
client.subscribe("json_data")
print("Connected with result code " + str(rc))
def on_message(client, userdata, message):
data_from_mqtt = json.loads(message.payload.decode())
connection = sqlite3.connect('mqtt.db')
cursor = connection.cursor()
cursor.execute('''CREATE TABLE IF NOT EXISTS mqtt_data
(id INT,first_name varchar(20),last_name varchar(20))''')
for data in data_from_mqtt:
cursor.execute("INSERT INTO mqtt_data VALUES (?,?,?)", (data["id"], data["first_name"],
data["last_name"]))
cursor.execute("SELECT * FROM mqtt_data")
datas = cursor.fetchall()
for row in datas:
print(row)
client = mqtt.Client()
client.on_message = on_message
client.connect("192.168.0.220", 1883, 60)
client.on_connect = on_connect
client.loop_forever()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment