Пример #1
0
extern "C" void loop() {
	Actor::eventLoop();
	if (WiFi.status() != WL_CONNECTED) {
		Serial.print("Connecting to ");
		Serial.print(WIFI_SSID);
		Serial.println("...");
		WiFi.begin(WIFI_SSID, WIFI_PSWD);

		if (WiFi.waitForConnectResult() != WL_CONNECTED) {
			LOGF(" still connecting ");
			return;
		}
		LOGF("WiFi connected");
	}

	if (WiFi.status() == WL_CONNECTED) {
//	if (wifi.connected()) {
		if (!client.connected()) {
			mdns.onWifiConnected(Header(INIT));
			IPAddress server = mdns.query("mqtt");
			client.set_server(server,1883);
			if (client.connect("wibo1", prefix + "system/alive", 1, 0,
					"false")) {
				client.publish(prefix + "system/alive", "true");
				client.set_callback(callback);
				client.subscribe(subscribe_topic);
				Log.setOutput(udpLog);
				LOGF(" mqtt client connected ");
			} else {
				LOGF(" mqtt connect failed ")
			}
		}
		if (client.connected())
			client.loop();
	}
Пример #2
0
void loadConfig() {
	String ssid, password, hostname, service, mqttHost;
	uint32_t mqttPort;
	char hostString[16] = { 0 };
	sprintf(hostString, "ESP_%06X", ESP.getChipId());

	waitConfig();

	Config.get("uart.baudrate", BAUDRATE, 115200);
	Config.get("wifi.ssid", ssid, WIFI_SSID);
	Config.get("wifi.pswd", password, WIFI_PSWD);
	Config.get("wifi.hostname", hostname, hostString);
	Config.get("mqtt.port", mqttPort, 1883);
	Config.get("mqtt.host", mqttHost, "test.mosquitto.org");
	Config.get("mqtt.prefix", prefix, "wibo1/bootloader/");
	subscribe_topic = "put/" + prefix + "#";

//TODO	wifi.setConfig(ssid, password, hostname);
//	udp.setConfig(udpPort);
//	mdns.setConfig(service, udpPort);
	client.set_server(mqttHost, mqttPort);

}