#include <Stepper.h>
int STEPS_PER_MOTOR_REVOLUTION=200;int MOTOR_SPEED = 20;int PINA;int PINB;int PINC;int PIND;
Stepper small_stepper;// FROM WEBserver Selection pinA,pinB,pinC,pinDvoid init(int pinA,int pinB,int pinC,int pinD) { // Declare 'small_stepper' variable PINA=pinA; PINB=pinB; PINC=pinC; PIND=pinD; small_stepper(STEPS_PER_MOTOR_REVOLUTION, PINA, PINB, PINC, PIND);}
// FROM MQTT STEPS_PER_MOTOR_REVOLUTION XXXvoid setRev(int rev){ STEPS_PER_MOTOR_REVOLUTION=rev; small_stepper = nothing; small_stepper(STEPS_PER_MOTOR_REVOLUTION, PINA, PINB, PINC, PIND);}
// FROM MQTT SPEED XXXvoid setSpeed(int speed){ MOTOR_SPEED=speed; small_stepper.setSpeed(MOTOR_SPEED); }
// FROM MQTT SPEED int getSpeed(){ return MOTOR_SPEED;}
// FROM MQTT STEP XXXvoid moveNumberOfSteps(int steps) small_stepper.step(steps);}
// FROM MQTT STEP +void moveForward() small_stepper.step(STEPS_PER_MOTOR_REVOLUTION);}
// FROM MQTT STEP -void moveBackward() small_stepper.step(-STEPS_PER_MOTOR_REVOLUTION);}Enter code here.../*Basic MQTT exampleThis sketch demonstrates the basic capabilities of the library.It connects to an MQTT server then:- publishes "hello world" to the topic "outTopic"- subscribes to the topic "inTopic", printing out any messagesit receives. NB - it assumes the received payloads are strings not binaryIt will reconnect to the server if the connection is lost using a blockingreconnect function. See the 'mqtt_reconnect_nonblocking' example for how toachieve the same result without blocking the main loop.*/#include <SPI.h>#include <Ethernet.h>#include <PubSubClient.h>// Update these with values suitable for your network.byte mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED };IPAddress ip(172, 16, 0, 100);IPAddress server(172, 16, 0, 2);void callback(char* topic, byte* payload, unsigned int length) {Serial.print("Message arrived [");Serial.print(topic);Serial.print("] ");for (int i=0;i<length;i++) {Serial.print((char)payload[i]);}Serial.println();}EthernetClient ethClient;PubSubClient client(ethClient);void reconnect() {// Loop until we're reconnectedwhile (!client.connected()) {Serial.print("Attempting MQTT connection...");// Attempt to connectif (client.connect("arduinoClient")) {Serial.println("connected");// Once connected, publish an announcement...client.publish("outTopic","hello world");// ... and resubscribeclient.subscribe("inTopic");} else {Serial.print("failed, rc=");Serial.print(client.state());Serial.println(" try again in 5 seconds");// Wait 5 seconds before retryingdelay(5000);}}}void setup(){Serial.begin(57600);client.setServer(server, 1883);client.setCallback(callback);Ethernet.begin(mac, ip);// Allow the hardware to sort itself outdelay(1500);}void loop(){if (!client.connected()) {reconnect();}client.loop();}
found in the pubsubclient arduino examples shows how to subscribe to a mqtt topic and receive the payload..
Thanks Phil,
You need to talk to Theo and add as a Pull Request in the Tasmota GitHub.
Regards
Phil K
Sent from Mail for Windows 10
--
You received this message because you are subscribed to the Google Groups "SonoffUsers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonoffusers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.