no exist communication what i have to do for happens communication
Post all code. Please don't post images of code but use code tags as described in How to get the best out of this forum.
Please try to give a better description of your problem.
Your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with (nor for advise on) your project.
Please post your entire code using Code Tags </> and show a circuit diagram of your project.
For I2C code see the example projects coming with the Wire library.
"
#include "Config.h"
#include "AP_v1.1l.h"
#define APMODE 100
#define CONNECTWIFI 200
#define WIFICONNECTED 300
#define IS_LOG true
String macString;
#define LED_AP 14
#define LED_WIFI 15
void setup()
{
Serial.print(115200);
Wire.begin(5, 4);
startAP();
step = APMODE;
macString = WiFi.macAddress();
macString.toCharArray(mac, 17);
id[0] = mac[0];
id[1] = mac[1];
id[2] = mac[3];
id[3] = mac[4];
id[4] = mac[6];
id[5] = mac[7];
id[6] = mac[9];
id[7] = mac[10];
id[8] = mac[12];
id[9] = mac[13];
id[10] = mac[15];
id[11] = mac[16];
idEquip = id;
}
void loop()
{
EEPROM.begin(512);
intervalo = EEPROM.read(10);
EEPROM.end();
//if(IS_LOG)Serial.print("STEP = ");
//if(IS_LOG)Serial.println(step);
switch (step)
{
case APMODE:
//começa a contar o tempo que vai estar em AP
apTime.start();
step = step + 2;
break;
case APMODE+1:
readCredentials();
connectWiFi();
if (timeout.Is() && (WiFi.softAPgetStationNum() == 0))
{
startAP();
step = APMODE;
count++;
}
break;
case APMODE + 2:
server.handleClient(); // Listen for HTTP requests from clients
//Serial.println("handle");
//if (apTime.Is()) //se passar o tempo que esta definido para ele estar em AP volta a tentar ligar-se as credenciais antigas se ninguem estiver ligado ao AP
if (apTime.Is() && (WiFi.softAPgetStationNum() == 0))
{
count = 0;
step = APMODE + 1;
timeout.start();
}
break;
case CONNECTWIFI:
connectWiFi();
Serial.println("A LIGAR");
digitalWrite(LED_AP, HIGH);
digitalWrite(LED_WIFI, HIGH);
break;
case WIFICONNECTED:
if (WiFi.status() != WL_CONNECTED)
{
Serial.println("falhou a net...");
startAP();
step = APMODE;
}
Serial.println("ESTOU LIGADO A NET E VOU LER O I2C");
requesti2c();
Serial.println("Trama 1");
Serial.println(Trama[1], HEX);
if (Trama[1] == intervalo)
{
Serial.println("CHEGUEI AO INTERVALO DE CICLOS PRETENDIDO");
updateCicles();
resetArduinoCicles();
}
Serial.println("Trama 2:");
Serial.println(Trama[2], HEX);
if (Trama[2] != L_Trama[2])
{
if (Trama[2] == 0x30)
{
desinfectantLevelStatus = 0;
}
else if (Trama[2] == 0x31)
{
desinfectantLevelStatus = 1;
}
updateAlarms(2);
L_Trama[2] = Trama[2];
}
Serial.println("Trama 3");
Serial.println(Trama[3], HEX);
if (Trama[3] != L_Trama[3])
{
if (Trama[3] == 0x30)
{
motorStatus = 0;
}
else if (Trama[3] == 0x31)
{
motorStatus = 1;
}
updateAlarms(3);
L_Trama[3] = Trama[3];
}
Serial.println("Trama 4");
Serial.println(Trama[4], HEX);
if (Trama[4] != L_Trama[4])
{
if (Trama[4] == 0x30)
{
descargaStatus = 0;
}
else if (Trama[4] == 0x31)
{
descargaStatus = 1;
}
updateAlarms(4);
L_Trama[4] = Trama[4];
}
Serial.println("Trama 5");
Serial.println(Trama[5], HEX);
if (Trama[5] != L_Trama[5])
{
if (Trama[5] == 0x30)
{
evDesinfStatus = 0;
}
else if (Trama[5] == 0x31)
{
evDesinfStatus = 1;
}
updateAlarms(5);
L_Trama[5] = Trama[5];
}
Serial.println("Trama 6");
Serial.println(Trama[6], HEX);
if (Trama[6] != L_Trama[6])
{
if (Trama[6] == 0x30)
{
dosinPumpStatus = 0;
}
else if (Trama[6] == 0x31)
{
dosinPumpStatus = 1;
}
updateAlarms(6);
L_Trama[6] = Trama[6];
}
int x = 0;
if (x = 0)
{
updateCicles();
x = 1;
}
step = WIFICONNECTED;
delay(1000);
break;
}
}
void handleRoot()
{ String idString(id);
String filetosend = file1 + idString + filex;
server.send(200, "text/html", filetosend);
}
void handleNotFound()
{
server.send(404, "text/plain", "404: Not found"); // Send HTTP status 404 (Not Found) when there's no handler for the URI in the request
}
void writeCredentials()
{
EEPROM.begin(512);
EEPROM.write(0, 49);
EEPROM.end();
//write SSID
for (int i = 1; i < 20; i++)
{
EEPROM.begin(512);
EEPROM.write((20 + i), ssid[i - 1]);
EEPROM.end();
}
//write Password
for (int i = 0; i < 20; i++)
{
EEPROM.begin(512);
EEPROM.write((50 + i), password[i]);
EEPROM.end();
}
if (IS_LOG) Serial.println("escritas credenciais ");
}
void readCredentials()
{
EEPROM.begin(512);
for (int i = 1; i < 20; i++)
{
ssid[i - 1] = EEPROM.read((i + 20));
if (IS_LOG) Serial.print(ssid[i - 1]);
}
if (IS_LOG) Serial.println(" ");
for (int i = 0; i < 20; i++)
{
password[i] = EEPROM.read((50 + i));
if (IS_LOG)Serial.print((char)password[i]);
}
if (IS_LOG)Serial.println(" ");
if (IS_LOG) Serial.println("Lidas credenciais ");
EEPROM.end();
}
void handlemanutencao()
{
server.send(200, "text/html", file2);
}
void handlemanutencaolog()
{
if ( ! server.hasArg("user") || ! server.hasArg("pass") || server.arg("user") == NULL || server.arg("pass") == NULL)
{
return;
}
String Manut_HTML = Manut_HTML1 + (String)intervalo + Manut_HTML2;
if (server.arg("user") == "Endovis" && server.arg("pass") == "endovis")
{
server.send(200, "text/html", Manut_HTML);
}
else
{ // Username and password don't match
server.send(401, "text/plain", "401: Não Autorizado");
}
}
void handlewifiPost()
{ // If a POST request is made to URI /login
if (!server.hasArg("username") || !server.hasArg("password") || server.arg("username") == NULL || server.arg("password") == NULL)
{
return;
}
else
{
user = server.arg("username");
if (IS_LOG)Serial.print("SSID: ");
if (IS_LOG)Serial.println(user);
pass = server.arg("password");
user.toCharArray(ssid, 20);
pass.toCharArray(password, 20);
if (IS_LOG)Serial.print("Password: ");
if (IS_LOG)Serial.println(pass);
server.send(400, "text/Connecting", "Tentando conectar ao WiFi... Este Access Point ira ficar inativo");
delay(500);
step = CONNECTWIFI;
}
}
void handlewifi()
{
server.send(200, "text/html", file3);
}
void handleresetcicles()
{
String resetCiclos = resetCiclos1 + (String)intervalo + resetCiclos2;
server.send(200, "text/html", resetCiclos);
}
void handleresetfabrica()
{
EEPROM.begin(512);
EEPROM.write(0, 48);
EEPROM.write(10, 10);
EEPROM.end();
intervalo = 10;
String resetFabrica = resetFabrica1 + (String)intervalo + resetFabrica2;
server.send(200, "text/html", resetFabrica);
}
void handlemanutencaologget()
{
String teste(id);
String Manut_HTML = Manut_HTML1 + (String)intervalo + Manut_HTML2;
server.send(200, "text/html", Manut_HTML);
}
void handleintervalos()
{
if (server.hasArg("intervalo"))
{
intervalochar = server.arg("intervalo");
intervalo = intervalochar.toInt();
EEPROM.begin(512);
EEPROM.write(10, intervalo);
intervalochar = server.arg("intervalo");
EEPROM.end();
String intervaloAlterado = intervaloAlterado1 + (String)intervalo + intervaloAlterado2;
server.send(200, "text/html", intervaloAlterado);
}
}
void startAP()
{
step = APMODE;
WiFi.mode(WIFI_AP);
WiFi.softAP("Endovis_AP", "987654321");
Serial.begin(115200); // Start the Serial communication to send messages to the computer
delay(10);
Serial.println('\n');
delay(250);
Serial.print('.');
if (MDNS.begin("esp8266"))
{
if (IS_LOG)Serial.println("mDNS responder started");
}
else
{
if (IS_LOG)Serial.println("Error setting up MDNS responder!");
}
server.on("/", HTTP_GET, handleRoot); // Call the 'handleRoot' function when a client requests URI "/"
server.on("/wifi", HTTP_GET, handlewifi);
server.on("/wifi", HTTP_POST, handlewifiPost); // Call the 'handleLogin' function when a POST request is made to URI "/login"
server.on("/manutencao" , HTTP_GET, handlemanutencao);
server.on("/manutencaolog" , HTTP_POST, handlemanutencaolog);
server.on("/manutencaolog" , HTTP_GET, handlemanutencaologget);
server.on("/resetcicles" , HTTP_GET, handleresetcicles);
server.on("/resetfabrica" , HTTP_GET, handleresetfabrica);
server.on("/intervalos" , HTTP_GET, handleintervalos);
server.onNotFound(handleNotFound); // When a client requests an unknown URI (i.e. something other than "/"), call function "handleNotFound"
server.begin(); // Actually start the server
if (IS_LOG)Serial.println("HTTP server started");
}
void connectWiFi()
{
WiFi.mode(WIFI_STA);
if (IS_LOG) Serial.println("SSID STRING: ");
Serial.println(ssid);
if (IS_LOG) Serial.println("pass STRING: ");
Serial.println(password);
WiFi.begin(ssid, password);
wifiTimeout.start();
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
if (wifiTimeout.Is())
{
if (IS_LOG) Serial.println("FAILED TO CONNECT");
startAP();
return;
}
if (IS_LOG) Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
step = WIFICONNECTED;
writeCredentials();
}
void requesti2c()
{
Serial.print("Passei aqui");
Wire.requestFrom(8, 14);
checksum = 0;
i = 0;
while (Wire.available())
{
Trama[i] = Wire.read();
Serial.print(Trama[i], HEX);
delay(50);
i++;
}
}
void resetArduinoCicles()
{
Wire.beginTransmission(8); // transmit to device #9
Wire.write(1); // sends one byte
Wire.endTransmission();
}
"
Hello, this is my code above im not very good in english but i can explain moreless the problems.
i have a pcb created by me and i use "Microchip Tech ATMEGA328P-AU" and a " Ai-Thinker ESP-12F(ESP8266MOD)" im triyng see the alarms on esp, im reading my owns "tramas" but when i go to serial monitor i dont read the value of my "tramas"
i have more codes this code is of esp-12
It's too much for a systematic search. If you have problems with I2C and the Wire library then run a master example on one controller and a slave example on the other one.
AFAIK your controllers are 5V and 3.3V so that you need a level shifter for the I2C bus.
i dont have problems with wire library i have problems on esp-12 because my "tramas" are looking for a specific number of my own "trama" and he can't indicate this number I'm looking for
Hello one more time, in time of war i can resolve my code the problems are "wire.begin" i put "wire.begin ()" instead "wire.begin (5,4)" and resolve the problem dont me ask why but its done thanks for all the help and sorry if my english is not the best guys.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.