Browse code

Added ports and started getting stuff ready to talk to board and MQTT :D

Richard Cornwell (K9RCP) authored on 03/15/2022 02:25:23
Showing 1 changed files
... ...
@@ -3,13 +3,34 @@
3 3
 #include <EthernetENC.h>
4 4
 #include <PubSubClient.h>
5 5
 
6
+
7
+int motorSpeedPin =   6;
8
+int motorUpPin =      2;
9
+int motorDownPin =    3;
10
+int motorLeftPin =    4;
11
+int motorRightPin =   5;
12
+int posTilt =         A0;
13
+int posPan =          A1;
14
+int motorSpeedStat =   0;
15
+
6 16
 // Update these with values suitable for your network.
7 17
 byte mac[]    = {  0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED };
8 18
 IPAddress ip(10, 13, 37, 165); 
9 19
 byte server[] = {10, 13, 37, 101};
10 20
 
11 21
 void callback(char* topic, byte* payload, unsigned int length) {
12
-  // handle message arrived
22
+
23
+  Serial.print("Message arrived [");
24
+  Serial.print(topic);
25
+  Serial.print("] ");
26
+  for (int i = 0; i < length; i++) {
27
+    Serial.print((char)payload[i]);
28
+  }
29
+  Serial.println("");
30
+
31
+
32
+
33
+  
13 34
 }
14 35
 
15 36
 EthernetClient ethClient;
... ...
@@ -17,6 +38,16 @@ PubSubClient client(server, 1883, callback, ethClient);
17 38
 
18 39
 void setup()
19 40
 {
41
+
42
+  pinMode(motorSpeedPin, OUTPUT);
43
+  pinMode(motorUpPin, OUTPUT);
44
+  pinMode(motorDownPin, OUTPUT);
45
+  pinMode(motorLeftPin, OUTPUT);
46
+  pinMode(motorRightPin, OUTPUT);
47
+
48
+  pinMode(posTilt, INPUT);
49
+  pinMode(posPan, INPUT);
50
+
20 51
   Serial.begin(9600);
21 52
   Ethernet.begin(mac, ip);
22 53
   client.setBufferSize(255);
... ...
@@ -30,10 +61,14 @@ void reconnect() {
30 61
     // Attempt to connect
31 62
     if (client.connect("connectionName", "[[USER]]", "[[PASS]]")) {
32 63
       Serial.println("connected");
33
-      // Once connected, publish an announcement...
34
-      client.publish("outTopic","hello world");
35
-      // ... and resubscribe
36
-      client.subscribe("inTopic");
64
+      client.publish("hamradio/rotator/status","READY");
65
+      client.subscribe("hamradio/rotator/#");
66
+        
67
+  client.publish("hamradio/rotator/motor/speed", "100");
68
+  client.publish("hamradio/rotator/pos/pan", "180");
69
+  client.publish("hamradio/rotator/pos/tilt", "60");
70
+  client.publish("hamradio/rotator/goto/pan", "180");
71
+  client.publish("hamradio/rotator/goto/tilt", "60");
37 72
     } else {
38 73
       Serial.print("failed, rc=");
39 74
       Serial.print(client.state());
... ...
@@ -50,4 +85,8 @@ void loop()
50 85
     reconnect();
51 86
   }
52 87
   client.loop();
88
+
89
+
90
+
91
+  
53 92
 }