0

Subscription does not work
Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
Please be positive and constructive with your questions and comments.

Subscription does not work

by AchimM on Thu Feb 06, 2020 10:28 am

Hi,

I am having the problem that the subscription was working fully fine but scince one week it is not working anymore.
Here is the code (only importan lines):

Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY);
Adafruit_MQTT_Publish T_send = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/temperature"); // Temperature
Adafruit_MQTT_Publish H_send = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/humidity"); // Humidity
Adafruit_MQTT_Publish P_send = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/pressure"); // Pressure
Adafruit_MQTT_Subscribe Vent = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME "/feeds/ventilator"); // Ventilator
Adafruit_MQTT_Subscribe Heat = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME "/feeds/heater"); // Heater
Adafruit_MQTT_Subscribe chosen_channel = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME "/feeds/channel");
volatile float DC_Vent=-666;
void setup() {
mqtt.connect();
mqtt.subscribe(&Vent); // Ventilator
mqtt.subscribe(&Heat); // Heater
mqtt.subscribe(&chosen_channel); // Channel
}
void loop() {
Adafruit_MQTT_Subscribe *subscription;
while ((subscription = mqtt.readSubscription(15000))) { // Read in data from the server and wait for 15s for it
DC_Vent=666;
if (subscription == &Vent) { // If reading "Ventilator"
DC_Vent = atof((const char*)Vent.lastread); // Convert string into integer
analogWrite(Ventilator, round(DC_Vent * 2.55)); // Set Ventilator value to the port
}
if (subscription == &Heat) { // If reading "Heater"
DC_Load = atof((const char*)Heat.lastread); // Convert string into integer
analogWrite(Load, round(DC_Load * 2.55)); // Set Ventilator value to the port
DC_Vent=1111;
}
if (subscription == &chosen_channel) { // If reading Channel
Channel = atoi((const char*)chosen_channel.lastread); // Convert string into integer
MUX.setChannel(Channel); // Set Ventilator value to the port
Channel = MUX.channel;
DC_Vent=22222;
}
}


The connection is fine as I am sending data and everything arrives properly. I added the value DC_Vent in several lines and send them back to the webside to see where it stops and it never enters the while as I never get one of the values insides it allways sends -666 as value. User Name and everything has to be correct as I can send data to the io server. As I said it was working perfectly till last week and found out now that it stopped coming inside the while meaning the subscription is not working.
Could anyone help me here? Did io adafruit changed something for the subscription? In the help I could not find a syntax change.....

The platform I am usind for programming is arduino.....

Best,
Achim

AchimM
 
Posts: 8
Joined: Mon Jul 01, 2019 10:40 am

Re: Subscription does not work

by brubell on Thu Feb 06, 2020 10:54 am

Could you post a screenshot from the Adafruit IO Webpage for /feeds/ventilator?

brubell
 
Posts: 745
Joined: Fri Jul 17, 2015 10:33 pm

Re: Subscription does not work

by AchimM on Thu Feb 06, 2020 11:18 am

brubell wrote:Could you post a screenshot from the Adafruit IO Webpage for /feeds/ventilator?


Hi for sure!

Thank you!
Attachments
io ventilator feed.png
io ventilator feed.png (309.83 KiB) Viewed 48 times

AchimM
 
Posts: 8
Joined: Mon Jul 01, 2019 10:40 am

Re: Subscription does not work

by brubell on Fri Feb 07, 2020 10:35 am

Code: Select all | TOGGLE FULL SIZE
DC_Vent=666;
if (subscription == &Vent) { // If reading "Ventilator"
DC_Vent = atof((const char*)Vent.lastread); // Convert string into integer
analogWrite(Ventilator, round(DC_Vent * 2.55)); // Set Ventilator value to the port


Could you print out the value of the vent after the if subscription conditional?

Code: Select all | TOGGLE FULL SIZE
Serial.print("Vent: ");Serial.println(DC_Vent);

brubell
 
Posts: 745
Joined: Fri Jul 17, 2015 10:33 pm

Re: Subscription does not work

by AchimM on Mon Feb 10, 2020 4:32 am

Hi,

yes I can tell you allready that he is not changing the value here. It is allready not changing the DC_Vent to 666 it stays at -666 which is the value that it gets in the void setup.
I just had one more idea what could be. I need to check if not the receiver pin of the ethernet module broke up just to be sure...

Thank you!

AchimM
 
Posts: 8
Joined: Mon Jul 01, 2019 10:40 am

Please be positive and constructive with your questions and comments.