Jump to content









Photo

mqtt micropython


  • Please log in to reply
1 reply to this topic

#1 M.fathy

M.fathy

    Newbie

  • Members
  • Pip
  • 4 posts

Posted 20 June 2018 - 09:22 PM

hello 

 

i am a bit new in carriots i want to create project with micropython Esp32 since the sdk example with 

paho.python and it not applicable for  micropython  (it use threading) i try to use umqtt .simple library 

https://github.com/m...umqtt/simple.py

i create  a client 

SERVER='api.carriots.com'
CLIENT_ID='ESP32_TIMER_counter'
TOPIC=b'Esp32@M.fathy.M.fathy'
port = '1883'
auth = {'username':'Api_key', 'password': '12'}
msg_dict = {'protocol': 'v2', 'device': 'Esp32@M.fathy.M.fathy', 'at': 'now', 'data': {"This": "Is a JSON example5","Carriots": {  "cool": True,"number": 123, "text": "Hello World","timer": 698989 }}}
Api_key='my_api_key'
device_id='mohamed.Esp32@M.fathy.M.fathy'
CLient = MQTTClient(TOPIC,SERVER,port,device_id,password)
CLient.connect()

then i try to publish with

CLient.publish(dumps(auth),dumps(msg_dict))

but it doesnt work any idea to create connection and publish data with micropython

 



#2 Yoleon

Yoleon

    Sugar Master

  • Members
  • PipPipPip
  • 47 posts

Posted 22 June 2018 - 10:05 AM

Hi M.fathy

 

You can send data streams or status streams through the public MQTT (mqtt.carriots.com). I'll give you an example:
 
- Host: mqtt.carriots.com
- Port: 1883 (normal) or 8883 (TLS)
- Topic: {your_apikey}/streams or {your_apikey}/status
- Username: {your_apikey}
- Password: empty
- Message: { "protocol": "v2", "device": "defaultDevice@M.fathy.M.fathy", "at": "now", "data": { "key": "value" } }
 
This broker is only for publish and all the publishes to the {your_apikey}/streams or {your_apikey}/status topics will create a stream or status in your carriots account.
 
I hope this helps you





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users