Skip to content

Reset Loop while using WebServer on 8266 #3

@neuhoffm-sh

Description

@neuhoffm-sh

I am trying to run a very basic web server (relevant code included below) and am stuck in a reset loop. The starting setup line is never reached. I am using platformio to include the library and compile the code. Ultimately, I'd like to be able to trigger two stepper motors and an LED from a website hosted on the ESP. I have tried a number of variations on how to construct the stepper object with the same result each time. Any ideas? Thanks!

#include <CheapStepper.h>
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>

CheapStepper stepper1 (D1,D2,D3,D4);
ESP8266WebServer server(80);

void setup() {
	Serial.begin(115200);
	Serial.println("starting setup");

	WiFi.mode(WIFI_AP);
	uint8_t mac[WL_MAC_ADDR_LENGTH];
	WiFi.softAPmacAddress(mac);
	String macID = String(mac[WL_MAC_ADDR_LENGTH - 2], HEX) +
		String(mac[WL_MAC_ADDR_LENGTH - 1], HEX);
	macID.toUpperCase();
	String AP_NameString = "IOT " + macID;

	char AP_NameChar[AP_NameString.length() + 1];
	memset(AP_NameChar, 0, AP_NameString.length() + 1);

	for (int i = 0; i<AP_NameString.length(); i++)
		AP_NameChar[i] = AP_NameString.charAt(i);

	WiFi.softAP(AP_NameChar);
	Serial.printf("Connect to Wi-Fi access point: %s\n", AP_NameChar);
	Serial.println("and open http://192.168.4.1 in your browser");

	stepper1.setRpm(12);
	stepper1.set4076StepMode();

	server.on("/motor", HTTP_POST, []() {
		uint8_t degrees = server.arg("degrees").toInt();
		stepper1.newMoveToDegree(true, degrees);
		String json = String("Received");
		server.send(200, "text/json", json);
		json = String();
	});

	server.begin();

	Serial.println("HTTP server started");

}

void loop() {
	server.handleClient();
	stepper1.run();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions