- Sun Mar 12, 2017 12:15 pm
#63606
martinayotte wrote:This is because GPIOs can drive LED or something else in 2 modes : sink or source modes.
This means a digitalWrite(pin, LOW) or digitalWrite(pin, HIGH) will provide either a GND or VCC.
So, it is inverting the logic ...
i have one more problem martin. my server side sometimes disappears from wifi connections list so client cant connect to it and system breaks down. why is that? as you can see in the picture i soldered rst pin to gpio16 using a 220 ohm resistor(i couldnt find 470 ohm, i dont know if that matters) and relay is connected to arduino 5v and esp also arduino 3.3v. relay's GND and ESP's GND are on the same line. before i soldered the resistor sometimes it used to stuck on blue led constantly flashing(i mean always on) . After i soldered i didnt see this happens but again as a result AP ends for a reason i dont know why. this is the last version of my code and i changed esp.reset to esp.restart( i dont know if i had to actually and i dont know the difference between them) and nothing good happened. so my question is what can i do to have a stable Access Point? Thanks
Code: Select all/*
Geekstips.com
IoT project - Communication between two ESP8266 - Talk with Each Other
ESP8266 Arduino code example
*/
#include <DHT.h>
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
int relay = 2;
// IoT platform Credentials
String apiKey = "7VIJ3X18MG7POOKI";
const char* logServer = "api.thingspeak.com";
// Internet router credentials
const char* ssid = "ESP8266";
const char* password = "12345678";
float h;
float t;
ESP8266WebServer server(80);
void setup() {
Serial.begin(74880);
WiFi.mode(WIFI_AP_STA);
setupAccessPoint();
pinMode(2, OUTPUT); // Make GPIO2 as an OUTPUT to drive Relay MOSFET
}
// Handling the / root web page from my server
void handle_index() {
server.send(200, "text/plain", "Get the f**k out from my server!");
}
// Handling the /feed page from my server
void handle_feed() {
String t = server.arg("temp");
String h = server.arg("hum");
long temp = t.toFloat();
if (temp < 22.0)
digitalWrite(relay, LOW); // Turn ON Relay on GPIO2
else
digitalWrite(relay, HIGH); // Turn OFF Relay on GPIO2
server.send(200, "text/plain", "This is response to client");
setupStMode(t, h);
}
void setupAccessPoint(){
Serial.println("** SETUP ACCESS POINT **");
Serial.println("- disconnect from any other modes");
WiFi.disconnect();
Serial.println("- start ap with SID: "+ String(ssid));
WiFi.softAP(ssid, password);
IPAddress myIP = WiFi.softAPIP();
Serial.print("- AP IP address is :");
Serial.print(myIP);
setupServer();
}
void setupServer(){
Serial.println("** SETUP SERVER **");
Serial.println("- starting server :");
server.on("/", handle_index);
server.on("/feed", handle_feed);
server.begin();
};
void setupStMode(String t, String v){
Serial.println("** SETUP STATION MODE **");
Serial.println("- disconnect from any other modes");
WiFi.disconnect();
Serial.println();
Serial.println("- connecting to Home Router SID: **********");
WiFi.begin("SUPERONLINE_WiFi_1074", "LYW7HFEFLCVH");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println();
Serial.println("- succesfully connected");
Serial.println("- starting client");
WiFiClient client;
Serial.println("- connecting to Database server: " + String(logServer));
if (client.connect(logServer, 80)) {
Serial.println("- succesfully connected");
String postStr = apiKey;
postStr += "&field1=";
postStr += String(t);
postStr += "&field2=";
postStr += String(v);
postStr += "\r\n\r\n";
Serial.println("- sending data...");
client.print("POST /update HTTP/1.1\n");
client.print("Host: api.thingspeak.com\n");
client.print("Connection: close\n");
client.print("X-THINGSPEAKAPIKEY: " + apiKey + "\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(postStr.length());
client.print("\n\n");
client.print(postStr);
}
client.stop();
Serial.println("- stopping the client");
Serial.println("- trying reset");
ESP.restart(); // If your ESP does not respond you can just *** reset after each request sending
}
void loop() {
server.handleClient();
}
before i forget, i also pulled GPIO0 high to 3.3v and also no good. And there is diode from arduino 5v to relay VCC.
You do not have the required permissions to view the files attached to this post.