a function-definition is not allowed here before '{' token

I'm trying to control blinds with a ESP8266 and Alexa.
I generated device ID’s with Sinric.com

When I create the loop I get Following error:

exit status 1
a function-definition is not allowed here before '{' token

This Is the part of the code that gives error: ( :frowning: Error cursor at this location when uploading)

void loop() {

webSocket.loop();

if(isConnected) {
uint64_t now = millis();

if((now - heartbeatTimestamp) > HEARTBEAT_INTERVAL) {
heartbeatTimestamp = now;
webSocket.sendTXT("H");
}
}
:frowning: void turnOn(String deviceId) {
if (deviceId == "5cf8de1d0837cc3a87c8faf5") // Device ID of first device
{
Serial.print("Turn on device id: ");
Serial.println(deviceId);

digitalWrite(relayPin, HIGH); // turn on relay with voltage HIGH
}
else {
Serial.print("Turn on for unknown device id: ");
Serial.println(deviceId);
}
}

void turnOff(String deviceId) {
if (deviceId == "5cf8de4d0837cc3a87c8faf7") // Device ID of first device
{
Serial.print("Turn off Device ID: ");
Serial.println(deviceId);

digitalWrite(relayPin, LOW); // turn off relay with voltage LOW
}
else {
Serial.print("Turn off for unknown device id: ");
Serial.println(deviceId);
}
}

You need to complete loop() before you start any other function definitions. If you use Ctrl-T (Tools/Auto Format ) in the IDE you'll see what's wrong. Braces {} must always pair up.

Steve

540/5000
I have adjusted the code and now it works without error. see the code at the bottom

but now I need this piece of code that must be repeated every time:

// Change direction when the stepper reaches the target position
if (stepper1.distanceToGo () == 0) {
stepper1.moveTo (-stepper1.currentPosition ());
}
stepper1.run ();
}

inserted below: void turnOn (String deviceId) {

when I insert it, the code is only runs once, that's why I thought it should be in the loop.

Do you have a solution?

void loop() {

webSocket.loop();

if (isConnected) {
uint64_t now = millis();

if ((now - heartbeatTimestamp) > HEARTBEAT_INTERVAL) {
heartbeatTimestamp = now;
webSocket.sendTXT("H");
}
}
}
void turnOn(String deviceId) {
if (deviceId == "5cf8de1d0837cc3a87c8faf5") // Device ID of first device
{
Serial.print("Turn on device id: ");
Serial.println(deviceId);

digitalWrite(relayPin, HIGH); // turn on relay with voltage HIGH
}
else {
Serial.print("Turn on for unknown device id: ");
Serial.println(deviceId);
}
}

void turnOff(String deviceId) {
if (deviceId == "5cf8de4d0837cc3a87c8faf7") // Device ID of first device
{
Serial.print("Turn off Device ID: ");
Serial.println(deviceId);

digitalWrite(relayPin, LOW); // turn off relay with voltage LOW
}
else {
Serial.print("Turn off for unknown device id: ");
Serial.println(deviceId);
}
}