arendst/Sonoff-MQTT-OTA-Arduino

no mqtt connection my sonoff TH 16

Open

#303 opened on Feb 6, 2017

 (6 comments) (0 reactions) (0 assignees)Arduino (196 forks)github user discovery
help wanted

Repository metrics

Stars
 (619 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

Hello, a few days before i received my first sonoff devices.

I installed MQtt server on my raspberry pi 3 using this wiki https://wiki.fhem.de/wiki/Sonoff#MQTT_Server_einrichten

# Repo install:
wget http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key
sudo apt-key add mosquitto-repo.gpg.key
cd /etc/apt/sources.list.d/
sudo wget http://repo.mosquitto.org/debian/mosquitto-wheezy.list
# or for jessie 
sudo wget http://repo.mosquitto.org/debian/mosquitto-jessie.list
sudo apt-get update
# mosquitto install and  client command mosquito_sub 
sudo apt-get install mosquitto mosquitto-clients

# MQTT Server Test
sudo service mosquitto status

with the result:


pi@raspberry ~ $ sudo service mosquitto status
● mosquitto.service - LSB: mosquitto MQTT v3.1 message broker
   Loaded: loaded (/etc/init.d/mosquitto)
   Active: active (running) since Sa 2017-01-28 18:22:32 CET; 1 weeks 1 days ago
  Process: 629 ExecStart=/etc/init.d/mosquitto start (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/mosquitto.service
           └─657 /usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf

Feb 02 23:55:12 raspberrypi systemd[1]: Started LSB: mosquitto MQTT v3.1 mes....
Feb 03 18:39:37 raspberrypi systemd[1]: Started LSB: mosquitto MQTT v3.1 mes....
Feb 03 18:49:19 raspberrypi systemd[1]: Started LSB: mosquitto MQTT v3.1 mes....
Warning: Journal has been rotated since unit was started. Log output is incomplete or unavailable.
Hint: Some lines were ellipsized, use -l to show in full.

Mqtt test on raspberry with ssh has worked fine with 2 ssh windows:

  1. one: mosquitto_sub -h localhost -v -t test
  2. one: mosquitto_pub -h localhost -t test -m "Test Mosquitto" Result in 1. window:

pi@raspberry ~ $ mosquitto_sub -h localhost -v -t test
test Test Mosquitto


In the webinterface of the sonoff console i get the following result:


00:00:00 APP: Project sonoff (Topic sonoff, Fallback DVES_1697CD, GroupTopic sonoffs) Version 3.1.2
00:00:00 Wifi: Connecting to AP1 HSHKH (XXXXXXXXXXXXXX) in mode 11N as sonoff-6093...
00:00:07 Wifi: Connected
00:00:07 HTTP: Webserver active on sonoff-6093 with IP address 192.168.178.29
19:00:36 MQTT: Attempting connection...
19:01:04 MQTT: Attempting connection...
19:01:21 MQTT: Attempting connection...
19:01:39 MQTT: Attempting connection...
19:01:56 MQTT: Attempting connection...
19:02:13 MQTT: Attempting connection...
19:02:30 RSLT: tele/sonoff/UPTIME = 1
19:02:30 MQTT: Attempting connection...
19:02:48 MQTT: Attempting connection...
19:03:05 MQTT: Attempting connection...
19:03:22 MQTT: Attempting connection...
19:03:39 MQTT: Attempting connection...
19:03:57 MQTT: Attempting connection...
19:04:14 MQTT: Attempting connection...
19:04:31 MQTT: Attempting connection...
19:04:41 RSLT: stat/sonoff/POWER = ON
19:04:48 MQTT: Attempting connection...
19:05:05 MQTT: Attempting connection...
19:05:23 MQTT: Attempting connection...
19:05:40 MQTT: Attempting connection...

In arendst software i have made the following changes:

#define STA_SSID               "SSID"      // Wifi SSID at home
#define STA_PASS               "password"  // Wifi password at home
#define WIFI_HOSTNAME          "%s-%04d"         // Expands to <MQTT_TOPIC>-<last 4 decimal chars of MAC address>



#define WIFI_CONFIG_TOOL       WIFI_WPSCONFIG    // Default tool if wifi fails to connect (WIFI_SMARTCONFIG, WIFI_MANAGER or WIFI_WPSCONFIG)
#define WIFI_CONFIG_TOOL       WIFI_WPSCONFIG    // Default tool if wifi fails to connect (WIFI_SMARTCONFIG, WIFI_MANAGER or WIFI_WPSCONFIG)
// Syslog
#define SYS_LOG_HOST           "Ip-Adresse-Server"

// MQTT
#define MQTT_HOST              "Ip-Adresse-Server"
#define MQTT_PORT              1883

"Ip-Adresse-Server" is the ip adress of my raspberry pi. This is the ip i use for ssh to communicate with my raspberry pi.

My sonoff still has no connection to mqtt on my raspberry.

Hope for your help.

Best regards, Kamil

Contributor guide