• Система автоматизации с открытым исходным кодом на базе esp8266/esp32 микроконтроллеров и приложения IoT Manager. Наша группа в Telegram

MQTTwarn

alfa2

New member
Добрый.

подумав изменил скрипт в папке /etc/init.d
mqttwarn
#!/bin/sh /etc/rc.common
# Script to start mqttwarn as a daemon for OpenWRT

START=95
STOP=10

DIR='/overlay/mosquitto'
BIN='python mqttwarn.py'
PIDFILE=/var/run/mqttwarn.pid

start() {
echo start
cd $DIR
start-stop-daemon -b -S -q -m -p $PIDFILE -x $BIN
}

stop() {
echo stop
start-stop-daemon -K -q -p $PIDFILE
rm -f $PIDFILE
}
перезапустил в люське mqttwarn. и о чудо заработало. данные пересылаются, график рисуется.

Теперь новая проблема с настройкой dioty.co, прошел регистрацию, получил пароль

в файл /etc/mosquitto/mosquitto.conf добавил строки
connection dioty
address mqtt.dioty.co:1883
topic ESP8266/CONTROL/# in 0 / /alfa@gmail.com/
topic ESP8266/STATUS/# out 0 / /alfa@gmail.com/
bridge_attempt_unsubscribe true
notifications false
keepalive_interval 60
start_type automatic
restart_timeout 30
try_private false
remote_username alfa@gmail.com
remote_password 12345678
из люськи перезапускаю mosquitto, в системном логе заветные строки не появляются. (перегружал и по питанию, без изменений)

куда копать?
 

alfa2

New member
сообщение не проходит, бридж похоже не поднимается

с логом у меня как то не получается

пробовал смотреть
sudo grep /var/log/syslog mosquitto | less
пусто

прописать в файл mosquitto.conf путь
log_dest file /overlay/mosquitto/mosquitto.log
не создается

в люське вижу только
Mon Nov 21 23:15:56 2016 user.emerg syslog: 1479759356: mosquitto version 1.4.7 (build date 2016-01-31 13:11:04+0100) starting
Mon Nov 21 23:15:56 2016 user.emerg syslog: 1479759356: Using default config.
Mon Nov 21 23:15:56 2016 user.emerg syslog: 1479759356: Opening ipv6 listen socket on port 1883.
Mon Nov 21 23:15:56 2016 user.emerg syslog: 1479759356: Opening ipv4 listen socket on port 1883.
 

alfa2

New member
Дополню логами
1479851356: mosquitto version 1.4.7 (build date 2016-01-31 13:11:04+0100) starting
1479851356: Config loaded from /etc/mosquitto/mosquitto.conf.
1479851356: Opening ipv6 listen socket on port 1883.
1479851356: Opening ipv4 listen socket on port 1883.
1479851356: Connecting bridge dioty (mqtt.dioty.co:1883)
1480277384: Bridge OpenWrt.dioty sending CONNECT
1480277384: Received CONNACK on connection local.OpenWrt.dioty.
1480277384: Bridge local.OpenWrt.dioty sending SUBSCRIBE (Mid: 1, Topic: /alfa@gmail.com/esp8266/CONTROL/#, QoS: 0)
1480277384: Bridge local.OpenWrt.dioty sending SUBSCRIBE (Mid: 2, Topic: /alfa@gmail.com/esp8266/STATUS/#, QoS: 0)
1480277384: Received SUBACK from local.OpenWrt.dioty
1480277384: Received SUBACK from local.OpenWrt.dioty
1480277384: Received PUBLISH from local.OpenWrt.dioty (d0, q0, r0, m0, '/esp8266/STATUS/GPIO/1', ... (5 bytes))
mqtt-spy к локальному mosquitto не подключается
в логе
1480277389: New connection from 192.168.200.14 on port 1883.
1480277389: Sending CONNACK to 192.168.200.14 (0, 5)
1480277389: Socket error on client <unknown>, disconnecting.
посылаю сообщение из топика Dioty
1480279257: Received SUBACK from local.OpenWrt.dioty
1480279257: Received SUBACK from local.OpenWrt.dioty
1480279257: Received PUBLISH from local.OpenWrt.dioty (d0, q0, r0, m0, '/esp8266/STATUS/GPIO/1', ... (5 bytes))
1480279264: Received PUBLISH from local.OpenWrt.dioty (d0, q0, r0, m0, '/alfa@gmail.com/esp8266/STATUS/', ... (5 bytes))
запускаю mqttwarn
1480279560: New connection from 192.168.200.201 on port 1883.
1480279560: Sending CONNACK to 192.168.200.201 (0, 5)
1480279560: Socket error on client <unknown>, disconnecting.
лог mqttwarn
2016-11-27 23:45:48,326 DEBUG [mqttwarn] Attempting connection to MQTT broker localhost:1883...
2016-11-27 23:45:48,329 DEBUG [mqttwarn] Setting LWT to clients/mqttwarn...
2016-11-27 23:45:48,344 INFO [mqttwarn] Starting 1 worker threads
2016-11-27 23:45:48,351 DEBUG [mqttwarn] Job queue has 0 items to process
2016-11-27 23:45:48,357 INFO [mqttwarn] Connection refused - not authorised
2016-11-27 23:45:48,362 WARNING [mqttwarn] Broker connection lost. Will attempt to reconnect in 5s...
2016-11-27 23:45:48,369 DEBUG [mqttwarn] Cannot decode JSON object, payload=Broker connection lost. Will attempt to reconnect in 5s...: No JSON object could be decoded
2016-11-27 23:45:48,381 DEBUG [mqttwarn] Message on brokerdisconnected going to log:debug
2016-11-27 23:45:48,385 DEBUG [mqttwarn] New `log:debug' job: brokerdisconnected
2016-11-27 23:45:48,390 DEBUG [mqttwarn] Message on brokerdisconnected going to file:mqttwarn
2016-11-27 23:45:48,394 DEBUG [mqttwarn] New `file:mqttwarn' job: brokerdisconnected
2016-11-27 23:45:48,398 DEBUG [mqttwarn] Processor #0 is handling: `log' for debug
2016-11-27 23:45:48,410 ERROR [mqttwarn] Cannot handle service=log, target=debug: KeyError('Invalid configuration: topic brokerdisconnected points to non-existing target debug in service log',)
2016-11-27 23:45:48,414 DEBUG [mqttwarn] Job queue has 1 items to process
 
Последнее редактирование:

alfa2

New member
если подумать с доками, Бридж все таки поднимается.
1480370682: Bridge local.OpenWrt.dioty doing local SUBSCRIBE on topic esp8266/STATUS/#
1480370682: Connecting bridge dioty (mqtt.dioty.co:1883)
1480370682: Bridge OpenWrt.dioty sending CONNECT
1480370682: Received CONNACK on connection local.OpenWrt.dioty.
1480370682: Bridge local.OpenWrt.dioty sending SUBSCRIBE (Mid: 11, Topic: esp8266/CONTROL/#, QoS: 0)
1480370682: Bridge local.OpenWrt.dioty sending UNSUBSCRIBE (Mid: 12, Topic: esp8266/STATUS/#)
1480370682: Received SUBACK from local.OpenWrt.dioty
1480370683: Received UNSUBACK from local.OpenWrt.dioty
Но mqtt-spy не подключаеся к локальному mosquitto и в логах сыпет ошибку
1480370705: Sending CONNACK to 127.0.0.1 (0, 5)
1480370705: Socket error on client <unknown>, disconnecting.
1480370711: New connection from 127.0.0.1 on port 1883.
лог mqttwarn
2016-11-27 23:45:45,526 INFO [mqttwarn] Starting mqttwarn
2016-11-27 23:45:45,531 INFO [mqttwarn] Log level is DEBUG
2016-11-27 23:45:45,565 DEBUG [mqttwarn] Service file loaded
2016-11-27 23:45:45,585 DEBUG [mqttwarn] Service log loaded
2016-11-27 23:45:48,322 DEBUG [mqttwarn] Service http loaded
2016-11-27 23:45:48,326 DEBUG [mqttwarn] Attempting connection to MQTT broker localhost:1883...
2016-11-27 23:45:48,329 DEBUG [mqttwarn] Setting LWT to clients/mqttwarn...
2016-11-27 23:45:48,344 INFO [mqttwarn] Starting 1 worker threads
2016-11-27 23:45:48,351 DEBUG [mqttwarn] Job queue has 0 items to process
2016-11-27 23:45:48,357 INFO [mqttwarn] Connection refused - not authorised
2016-11-27 23:45:48,362 WARNING [mqttwarn] Broker connection lost. Will attempt to reconnect in 5s...
2016-11-27 23:45:48,369 DEBUG [mqttwarn] Cannot decode JSON object, payload=Broker connection lost. Will attempt to reconnect in 5s...: No JSON object could be decoded
2016-11-27 23:45:48,381 DEBUG [mqttwarn] Message on brokerdisconnected going to log:debug
2016-11-27 23:45:48,385 DEBUG [mqttwarn] New `log:debug' job: brokerdisconnected
2016-11-27 23:45:48,390 DEBUG [mqttwarn] Message on brokerdisconnected going to file:mqttwarn
2016-11-27 23:45:48,394 DEBUG [mqttwarn] New `file:mqttwarn' job: brokerdisconnected
2016-11-27 23:45:48,398 DEBUG [mqttwarn] Processor #0 is handling: `log' for debug
2016-11-27 23:45:48,410 ERROR [mqttwarn] Cannot handle service=log, target=debug: KeyError('Invalid configuration: topic brokerdisconnected points to non-existing target debug in service log',)
2016-11-27 23:45:48,414 DEBUG [mqttwarn] Job queue has 1 items to process
2016-11-27 23:45:48,417 DEBUG [mqttwarn] Processor #0 is handling: `file' for mqttwarn
2016-11-27 23:45:48,434 DEBUG [file] *** MODULE=services/file.py: service=file, target=mqttwarn
2016-11-27 23:45:48,443 DEBUG [mqttwarn] Job queue has 0 items to process
2016-11-27 23:45:54,416 INFO [mqttwarn] Connection refused - not authorised
при подключении ESPишки
1480370705: Sending CONNACK to 192.168.200.201 (0, 5)
1480370705: Socket error on client <unknown>, disconnecting.
1480370711: New connection from 192.168.200.201 on port 1883.
без секции DioTy в конфиге mosquitto, все работает/подключается/пересылает.

направьте, что еще почитать, OpenWRT (линукса) вижу в первые.
 
Последнее редактирование:

alfa2

New member
Попробуйте в ini файл добавить
Код:
[/myTopic]
targets = file:data
так не будет обрабатываться секция, правильно
Код:
[myTopic]
targets = file:data
и файл mqtt-data.log создаcтся и информация добавляться будет.
файл mqttwarn.err создается только при наличии ошибки, нет ошибки, нет файла.
 

alfa2

New member
От esp8266 периодически приходят mqtt сообщения о температуре и влажности в темы /home/out/esp_temp1 и /home/out/esp_hum1. Как мне нужно написать блок настроек для thingspeak.com в mqttwarn, чтобы отправлять получаемые значения в качестве field1 и field2?
Для передачи данных с нескольких топиков, лучше использовать API, секция thingspeak описана на GitHub GitHub - jpmens/mqttwarn: Subscribe to MQTT topics (with wildcards) and notifiy pluggable services, сам настраивал, работает на ура.
Можно отправлять сразу, можно дождаться последнего и передать пакетом. Периодичность лучше настроить в esp8266.
 
Последнее редактирование:

Senya

New member
Всем привет !
Вот мои грабли :
Cannot connect to MQTT broker at localhost:1883: object of type 'int' has no len()
Решение оказалось проще простого в ini файле пароль был из цифр и воспринимался как int
поэтому пароль лучше писать в кавычках
password = '12345'
 

Senya

New member
Еще вопрос такой же как был у Nikita
есть много топиков sensors/rssi , sensors/dhth1, sensors/dhtt1
не знаю как сконфигурировать передачу на thingspeak этих значений
пробую так
[config:http]
timeout = 60
targets = {
#method #URL # query params or None # list auth
'thingspeak' : [ "get", "http://api.thingspeak.com/update?ke...d1={sensors/dhth1}&amp;field2={sensors/dhtt1}", None, None ]
}
[sensors/dhth1]
[sensors/dhtt1]
targets = http:thingspeak

но получается принять только 1 топик , и ни один не передается

2016-12-23 21:50:05,348 DEBUG [mqttwarn] Setting LWT to clients/mqttwarn...
2016-12-23 21:50:05,358 INFO [mqttwarn] Starting 1 worker threads
2016-12-23 21:50:05,363 DEBUG [mqttwarn] Job queue has 0 items to process
2016-12-23 21:50:05,368 DEBUG [mqttwarn] Connected to MQTT broker, subscribing to topics...
2016-12-23 21:50:05,371 WARNING [mqttwarn] Section `sensors/dhth1' has no targets defined
2016-12-23 21:50:05,375 DEBUG [mqttwarn] Subscribing to sensors/dhtt1 (qos=0)
2016-12-23 21:50:05,389 DEBUG [mqttwarn] Message received on sensors/dhtt1: -9.2
2016-12-23 21:50:05,392 WARNING [mqttwarn] Section `sensors/dhth1' has no targets defined
2016-12-23 21:50:05,396 DEBUG [mqttwarn] Section [sensors/dhtt1] matches message on sensors/dhtt1. Processing...
2016-12-23 21:50:05,401 DEBUG [mqttwarn] Cannot decode JSON object, payload=-9.2: 'float' object has no attribute 'items'
2016-12-23 21:50:05,410 DEBUG [mqttwarn] Message on sensors/dhtt1 going to http:thingspeak
2016-12-23 21:50:05,413 DEBUG [mqttwarn] New `http:thingspeak' job: sensors/dhtt1
2016-12-23 21:50:05,416 DEBUG [mqttwarn] Processor #0 is handling: `http' for thingspeak
2016-12-23 21:50:05,430 DEBUG [http] *** MODULE=services/http.py: service=http, target=thingspeak
2016-12-23 21:50:06,865 DEBUG [mqttwarn] Job queue has 0 items to process
2016-12-23 21:50:25,554 DEBUG [mqttwarn] Message received on sensors/dhtt1: -9.1
2016-12-23 21:50:25,561 WARNING [mqttwarn] Section `sensors/dhth1' has no targets defined
2016-12-23 21:50:25,565 DEBUG [mqttwarn] Section [sensors/dhtt1] matches message on sensors/dhtt1. Processing...
2016-12-23 21:50:25,570 DEBUG [mqttwarn] Cannot decode JSON object, payload=-9.1: 'float' object has no attribute 'items'
2016-12-23 21:50:25,575 DEBUG [mqttwarn] Message on sensors/dhtt1 going to http:thingspeak
2016-12-23 21:50:25,578 DEBUG [mqttwarn] New `http:thingspeak' job: sensors/dhtt1
2016-12-23 21:50:25,581 DEBUG [mqttwarn] Processor #0 is handling: `http' for thingspeak
2016-12-23 21:50:25,595 DEBUG [http] *** MODULE=services/http.py: service=http, target=thingspeak
2016-12-23 21:50:25,962 DEBUG [mqttwarn] Job queue has 0 items to process
 

Senya

New member
используйте API так проще, выше писал об этом
смотрю ссылку , а как свои данные подставить не пойму ...
[config:http]
timeout = 60

targets = {
#method #URL # query params or None # list auth # Json
'get1' : [ "get", "Example Domain", { 'q': '{name}', 'isod' : '{_dtiso}', 'xx': 'yy' }, ('username', 'password') ],

или не туда смотрю ???
 
Сверху Снизу