MQTT connection to ThingSpeak from local Mosquitto broker - Not authorized | ThingSpeak API | Forum

Avatar

Please consider registering
Guest

Search

— Forum Scope —






— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

Register Lost password?
sp_Feed sp_TopicIcon
MQTT connection to ThingSpeak from local Mosquitto broker - Not authorized
Avatar
Boggie
New Member
Forum Posts: 4
sp_UserOfflineSmall Offline
1
August 11, 2017 - 3:31 pm
sp_Permalink sp_Print

I'm trying to set up a connection from my local mosquitto mqtt broker to thingspeak, so I can run everything through my local broker and still log some of the data to thingspeak by creating a topic subtree starting with remote/thingspeak.

I have Mosquitto up and running and can pub and sub as expected, but when I try to configure the thingspeak connection things start to get weird.

Having read the mqtt documentation on thingspeaks api pages, I have come up with this mosquitto.conf file (I put in the cleansession true, everything I found about will-something appears to be 0 by default):

thingspeak.conf:
-----------------------------
connection thingspeak
address mqtt.thingspeak.com:1883
cleansession true
topic # out 0 remote/thingspeak/ channels/
-----------------------------

When I start my server, it tries to connect, but the connection gets refused:

1502479267: Connecting bridge thingspeak (mqtt.thingspeak.com:1883)
1502479267: Bridge raspberrypi.thingspeak sending CONNECT
1502479267: Received CONNACK on connection raspberrypi.thingspeak.
1502479267: Connection Refused: not authorised
1502479267: Socket error on client raspberrypi.thingspeak, disconnecting.

This is before I even try to publish a message through the connection.

What I was hoping this configuration would allow me to do, was publish a message with values to remote/thingspeak/<channelid>/publish/<write key> and make Mosquitto forward it to thingspeak on the topic channels/<channelid>/publish/<write key> 

Does anyone out there has a working thingspeak configuration for Mosquitto they can share? 🙂

Avatar
Boggie
New Member
Forum Posts: 4
sp_UserOfflineSmall Offline
2
August 14, 2017 - 3:39 pm
sp_Permalink sp_Print

Just to answer my own question, in case anyone else with the same challenge finds it.

After a lot of trial, error and looking at other bridge configurations on the internet, I found out that I needed to turn off notifications. The following bridge configuration will allow you to bridge messages from a local mosquitto server to thingspeak 🙂

-----
connection thingspeak
address mqtt.thingspeak.com
notifications false
cleansession true
topic # out 0 remote/thingspeak/ channels/
-----

Happy MQTT'ing

Avatar
RobO
New Member
Forum Posts: 1
sp_UserOfflineSmall Offline
3
August 16, 2017 - 2:35 am
sp_Permalink sp_Print

This may be related to an issue I am having.   I am running HomeAssistant on a RaspberryPI.  It uses Paho, or Mosquitto or some sort of MQTT broker.  Any way, I am sending & logging some weather data from an ESP8266 to HomeAssistant, through the MQTT broker.  I read the data, send it mqtt to home assistant, then post it to thingspeak.  I noticed that when I "ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);" , it drops my MQTT connection to HomeAssistant and must reconnect.

I use the lastwill feature and when they drop "OFFLINE", then I get a notification.  The weird thing is that the keep alive time is about 5 minutes.  I was getting a offline and reconnected notifications about every 30 seconds or so.  I edited out the thingspeak.writefields line and the issue went away.   Then I searched and your post came up.   I am thinking its the two different MQTT services causing my problem. 

So, do you think there is a workaround for this issue?  Can I somehow separate the two mqtt messages being sent to two different mqtt services on the same device? 

I am pretty new to mqtt & these little microcontrollers.  I have been curious if there was a way to send the same data to two different HomeAssistant installations from the same device, but I dont have enough knowledge about it.  After looking at the code, it looks like two different mqtt servers could be declared in the variables, but the thingspeak server is already declared as something different so I am still confused.

Anyway, if you could offer some suggestions I would greatly appreciate it.   Right now my setup is working, just for some reason it is dropping my mqtt connection to home assistant every time I send a post to my thingspeak channel.  I have to turn off the notifications for the dropped connections or I constantly get them. 

 

Rob

Avatar
JasonW

Forum Posts: 12
sp_UserOfflineSmall Offline
4
August 16, 2017 - 10:38 am
sp_Permalink sp_Print

RobO,

I don't think your problem is related to Boggie's post.  He is referring to publishing messages to the mqtt interface of ThingSpeak.  As far as I know, the ThingSpeak HomeAssistant component is using the HTTP REST interface.

It sounds like there is a problem with your ThingSpeak configuration.  If the ThingSpeak call errors out, it may be causing your HomeAssistant process to restart and in the process booting your ESP8266 mqtt client.

Forum Timezone: America/New_York

Most Users Ever Online: 114

Currently Online:
18 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 247

Vinod: 140

piajola: 71

vespapierre: 63

Adarsh_Murthy: 59

chrisjmears: 54

Newest Members:

DFence

HariKrishan

guya

Vicky66

RobO

Gottmoz9

Forum Stats:

Groups: 4

Forums: 17

Topics: 1209

Posts: 4235

 

Member Stats:

Guest Posters: 1

Members: 5480

Moderators: 0

Admins: 2

Administrators: Hans, lee