Please Log in or Create an account to join the conversation.
Dennis wrote: You could try to use the arduino IDE for esp8266, I've the imprwssion that it runs much more stable, and C is also easier for me than writing in lua...
see
github.com/esp8266/Arduino
regards
// www.arduinesp.com
//
// Plot DTH11 data on thingspeak.com using an ESP8266
// April 11 2015
// Author: Jeroen Beemster
// Website: www.arduinesp.com
#include <DHT.h>
#include <ESP8266WiFi.h>
// replace with your channel's thingspeak API key,
//String apiKey = "4XZ9NA14HQZ7BYD7";
const char* ssid = "MiFi";
const char* password = "nexusdroit";
//const char* server = "api.thingspeak.com";
#define DHTPIN 2 // what pin we're connected to
DHT dht(DHTPIN, DHT11,15);
WiFiServer server(8);
void setup() {
Serial.begin(115200);
delay(10);
dht.begin();
WiFi.begin(ssid, password);
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
}
void loop() {
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" degrees Celcius Humidity: ");
Serial.print(h);
Serial.println("% send to Thingspeak");
Serial.println("Waiting...");
delay(20000);
}
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
Dennis wrote: I used a nodeMCU firmware 0.9.4 (will have to check build number; see first post of my nodeMCU thread for a link), and also 0.9.5 (20150213) successfully.
Did you upload all three file from the github repo to the nodeMCU module, then rebooted it?
regards
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
EasyIoT wrote: In LUA example you can see how to send data to EasyIoT server:
iot-playground.com/2-uncategorised/36-es...demcu-lua-no-arduino
For analog signal use ControlLevel. For example:
http://192.168.1.8/Api/EasyIoT/Control/Module/Esp8266/N1S12/ControlLevel/14.5/
private void sendCommand(string value)
{
sendToServer("/gpio/"+value);
}
private void sendToServer(String message)
{
try
{
//Console.WriteLine("TCP client command:" + message);
Int32 port = 80;
System.Net.Sockets.TcpClient client = new System.Net.Sockets.TcpClient( ESP8266_IP_ADDRESS, port);
Byte[] data = System.Text.Encoding.ASCII.GetBytes(message);
System.Net.Sockets.NetworkStream stream = client.GetStream();
stream.Write(data, 0, data.Length);
// Close everything.
stream.Close();
client.Close();
}
catch(Exception e)
{
Console.WriteLine(e.StackTrace);
}
}
// Wait until the client sends some data
Serial.println("new client");
while(!client.available()){
delay(1);
}
// Read the first line of the request
String req = client.readStringUntil('\r');
Serial.println(req);
client.flush();
// Match the request
int val;
if (req.indexOf("/gpio/0") != -1)
val = 0;
else if (req.indexOf("/gpio/1") != -1)
val = 1;
else {
Serial.println("invalid request");
client.stop();
return;
}
// Set GPIO2 according to the request
digitalWrite(2, val);
client.flush();
// Prepare the response
String s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>\r\nGPIO is now ";
s += (val)?"high":"low";
s += "</html>\n";
// Send the response to the client
client.print(s);
delay(1);
Serial.println("Client disonnected");
http://192.168.1.8/Api/EasyIoT/Control/Module/Esp8266/N1S12/ControlLevel/14.5/
Please Log in or Create an account to join the conversation.