I’m trying to compile a sketch and the progress bar on the compiler only gets about 1/4 of the way through and just hangs. The messages in the lower part of the screen repeat the following lines over and over again:
at java.util.regex.Pattern$GroupHead.match(Pattern.java:4658)
at java.util.regex.Pattern$Loop.match(Pattern.java:4785)
at java.util.regex.Pattern$GroupTail.match(Pattern.java:4717)
at java.util.regex.Pattern$BranchConn.match(Pattern.java:4568)
at java.util.regex.Pattern$CharProperty.match(Pattern.java:3777)
I searched for similar problems but only found cases where someone had an unterminated string or was trying to use multi-line strings. Any help would be appreciated. Here is my sketch:
/**
* amqtt.ino
*
* Subscribes to MQTT messages and takes action
*/
#define OFF 0
#define ON 1
#define RF_XMIT_PIN 10
/* Each Walgreen's remote control light module is capable of controlling three units
plus an additional code for all three units at the same time. A zone is a separate
module, which has a separate set of codes*/
#define MAX_ZONES 2
#include <stdio.h>
#include <SPI.h>
#include <Ethernet.h>
#include <PubSubClient.h>
#include "RCSwitch.h"
/* light control module */
struct arduinoSwitch {
byte zone; // zone number
byte zoneIndex; // zone index in array
String name; // name of device
String room; // device room
unsigned long code[2]; // OFF and ON codes to issue
};
// three devices plus 1 for all devices = 4
arduinoSwitch switches[MAX_ZONES * 4];
// used to build array
static byte num = -1;
// Ethernet setup
byte mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED };
byte server[] = { 10, 16, 2, 21 };
byte ip[] = { 10, 16, 2, 150 };
EthernetClient ethClient;
// Arduino MQTT library
PubSubClient client(server, 1883, processMQTT, ethClient);
// 433 MHz RF Library
static RCSwitch remote = RCSwitch();
/**
* Called when an MQTT message is received. Skip or take action.
*
* @param *top - pinter MQTT Topic character array
* @param *payload - pointer to MQTT Payload array
* length - length of payload array
*/
void processMQTT(char *top, byte *payload, unsigned int length) {
byte sw = -1; // the switch that matches the command phrase
byte i=0; // loop variable
byte last = MAX_ZONES * 4; // last zone
bool done = false; // loop variable
// topic is command phrase, payload is "on" or "off"
String topic = String(top);
Serial.println(topic);
// check to see if command phrase matches one for our devices
while (i < last && !done) {
String action = "action/" + switches[i].room + "/motion";
String command = "cmd/" + switches[i].name;
if (topic == action || topic == command) {
sw = i;
done = true;
}
i++;
}
// no match
if (!done) return;
/* get payload ("on" or "off") */
char *p = (char*)malloc(length);
for (i = 0; i < length; i++) {
*(p + i) = tolower((char *)(payload + i));
}
*(p + length) = '\0';
Serial.println(p);
byte status = (strcmp(p, "on") == 0) ? ON : OFF;
free(p);
Serial.println(status);
// set zone pulse length
switch (switches[sw].zone) {
case 1:
remote.setPulseLength(292);
break;
case 2: default:
remote.setPulseLength(286);
break;
}
// send remote control code
remote.send(switches[sw].code[status], 25);
// respond with an MQTT status update
String payloadOut = status ? "True" : "False";
String topicOut = "status/" + switches[sw].room + "/" + switches[sw].name;
client.publish(topicOut, payloadOut);
Serial.print("Topic: ");
Serial.print(topicOut);
Serial.print(" | Payload: ");
Serial.println(payloadOut);
}
/**
* Initialize switches array with zone, name, room and on/off codes
*/
void setupSwitches(void) {
init(1, "fountain", office", 613902, 613918);
init(1, "front_light_2", "front", 613894, 613910);
init(1, "foyer_switch_1", "foyer", 613898, 613914);
init(1, "all_zone_1", "zone_1", 613904, 613896);
init(2, "foyer_switch_2", "foyer2", 14352654, 14352670);
init(2, "zone_2_device_2", "zone_2", 14352646, 14352662);
init(2, "zone_2_device_3", "zone_2", 14352650, 14352666);
init(2, "all_zone_2", "zone_2", 14352656, 14352648);
}
/*
* Constructor for switches object
*
* @param zone - zone number
* @param name - device name
* @param room - device's room
* @param codeOff - code to send to turn device off
* @param codeOn - code to send to turn device on
*/
void init(byte zone, String name, String room, unsigned long codeOff, unsigned long codeOn) {
++num;
switches[num].zone = zone;
switches[num].zoneIndex = zone-1;
switches[num].name = name;
switches[num].room = room;
switches[num].code[OFF] = codeOff;
switches[num].code[ON] = codeOn;
}
/**
* Set up serial port (for debugging), Ethernet for MQTT communication and
* 433MHz RF switch for remote control
*/
void setup() {
Serial.begin(9600);
Ethernet.begin(mac, ip);
/* remote control */
remote.setProtocol(1);
remote.setRepeatTransmit(5);
remote.enableTransmit(RF_XMIT_PIN);
/* conmnect and subscribe to MQTT Broker */
if (client.connect("arduinoClient")) {
Serial.println("Connected!");
Serial.println("Subscribing...");
client.subscribe("action/#");
client.subscribe("cmd/#");
} else {
Serial.println("Not Connected!");
}
}
/**
* Wait for an MQTT message
*/
void loop() {
client.loop();
}