I am trying to turn the servo certain degrees using Arduino cloud and it working but i want to find some logical errors in my code, for that purpose I want to use the serial monitor for printing the results but whenever I click the serial monitor on cloud editor my device turn offline, the moment i close the serial monitor window or pause it, the device status turn back to online. The code for the sketch is pasted below.
Settings of Flavours:
Upload Speed: 115200
CPU Frequency: 80 MHz
Flash Size: 4M (no SPIFFS)
Debug port: Disabled
Debug Level: None
lwIP Variant: v2 Lower Memory
VTables: Flash
Exceptions: Disabled
Erase Flash: Only Sketch
The code for the sketch is pasted below:
/*
Sketch generated by the Arduino IoT Cloud Thing "Untitled"
https://create.arduino.cc/cloud/things/7a2f6062-15f2-4350-aae9-7f9a79a8c6e6
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
String temp;
int dd_schedule;
int servo;
CloudSchedule schedule1;
CloudSchedule schedule2;
Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
which are called when their values are changed from the Dashboard.
These functions are generated with the Thing and added at the end of this sketch.
*/
#include "thingProperties.h"
#include <Servo.h>
Servo servo1;
int CurServoValue;
String tempText;
bool sch1Status = false;
bool sch2Status = false;
void setup() {
// Initialize serial and wait for port to open:
Serial.begin(115200);
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
delay(1500);
CurServoValue = 0;
servo1.attach(D1);
servo1.write(CurServoValue);
Serial.println("Hello World");
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
/*
The following function allows you to obtain more information
related to the state of network and IoT Cloud connection and errors
the higher number the more granular information you’ll get.
The default is 0 (only errors).
Maximum is 4
*/
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
}
void loop() {
ArduinoCloud.update();
// Your code here
CurServoValue = servo;
if(dd_schedule == 0 || dd_schedule == NULL)
{
servo1.write(CurServoValue);
temp = tempMsg(CurServoValue);
Serial.println("Running in Manual");
}
else if(dd_schedule == 1)
{
execSch1();
}
else if(dd_schedule == 2)
{
execSch1();
execSch2();
}
}
void execSch1()
{
Serial.print("In execSch1");
if(schedule1.isActive())
{
Serial.print("SCH 1 Active");
sch1Status = true;
if(CurServoValue == 0)
scheduler1(155, "MID HOT");
else
{
scheduler1(CurServoValue, tempMsg(CurServoValue));
}
}
else
{
if(sch1Status = true)
{
CurServoValue = 0;
servo1.write(CurServoValue);
temp = tempMsg(CurServoValue);
Serial.print("SCH 1 OFF");
sch1Status = false;
}
else
{
Serial.print("Running in Auto-Manual");
servo1.write(CurServoValue);
temp = tempMsg(CurServoValue);
}
}
}
void execSch2()
{
Serial.print("In execSch2");
if(schedule2.isActive())
{
Serial.print("SCH 2 Active");
sch2Status = true;
if(CurServoValue == 0)
scheduler2(155, "MID HOT");
else
scheduler2(CurServoValue, tempMsg(CurServoValue));
}
else
{
if(sch2Status = true)
{
CurServoValue = 0;
servo1.write(CurServoValue);
temp = tempMsg(CurServoValue);
Serial.print("SCH 1 OFF");
sch2Status = false;
}
else
{
Serial.print("Running in Auto-Manual");
servo1.write(CurServoValue);
temp = tempMsg(CurServoValue);
}
}
}
void scheduler1(int servoVal, String tempStatus)
{
servo1.write(servoVal);
temp = "SCH 1 " + tempStatus;
Serial.print("SCH 1 Active: " + servoVal);
}
void scheduler2(int servoVal, String tempStatus)
{
servo1.write(servoVal);
temp = "SCH 2 " + tempStatus;
Serial.print("SCH 2 Active" + servoVal);
}
String tempMsg(int servoVal)
{
String result;
if(servoVal == 0)
{
result = "OFF";
}
else if(servoVal == 57)
{
result = "WARM";
}
else if(servoVal == 105)
{
result = "HOT";
}
else if(servoVal == 155)
{
result = "MID HOT";
}
else if(servoVal == 180)
{
result = "VERY HOT";
}
Serial.print("Current Temp: " + result);
return result;
}
1 post - 1 participant