if that's the case I would assume that your ssid,password maybe wrong.
Also remember that the ESP8266 is a 3.3V device, so if you connect a 5V Arduino you will need a level converter.
Explore... Chat... Share...
Moderator: igrr
int getValue() {
Wire.beginTransmission(SlaveDeviceId);
Wire.write(1); // Transfer command ("1") to get X sensor value;
Wire.endTransmission(); // Moved up here by frippe75
delay(100);
// GET RESPONSE
int receivedValue1 = 0;
String valprimit = "";
//String c = "";
Wire.requestFrom(SlaveDeviceId, 1);
receivedValue1 = Wire.read();// << 8 | Wire.read(); // combine two bytes into integer
/*if (2 <= Wire.available()) {
//receivedValue1 = Wire.read();
//receivedValue1 = receivedValue1 << 8;
//receivedValue1 |= Wire.read();
}*/
valprimit = String(receivedValue1);
valprimit.toCharArray(valoare, 20);
client.publish("outTopic", valoare);
int error = Wire.endTransmission();
return receivedValue1;
}
case 1:{ // Return X sensor value
returnValue = getValue();
Serial.print("returnValue este:"); Serial.println(returnValue);
byte b[1];
b[0] = returnValue & 0xFF;
Serial.println(b[0]);
Wire.write(b, 2);
break;}
case 8: { // Return Y sensor value
returnValue = setPin();
byte buffer[1];
//buffer[0] = returnValue >> 8;
buffer[0] = returnValue & 0xff;
Wire.write(buffer, 1);
Serial.print(buffer[0]);
// null last Master's command
break;}
int getValue() {
float val1 = analogRead(SensorPin);
val1 = (val1*5/1024.0) - 0.5;
val1 = val1 / 0.01;
int val = (int) val1;
//int val = 22; // with a static
//Serial.println((int)val);
//val = (val - .5) * 100;
//int val = analogRead(SensorPin);
return val;
}
Erni wrote:Hi bogdanioanliviu,
As far as I can see, you are calling command 1 to get a value (2 bytes), but you only read 1 byte on the esp8266
But case 1 returns 2 byte.
In my example I let both cases return 2 bytes to avoid confusing myself.
It takes about 20-25 seconds for home assistant c[…]
I tried to upgrade tof my sonoff basic R2 with the[…]
a problem Perhaps you want to define "Probl[…]
Rebooting your router will not give you a faster I[…]
There are no other notifications from esptool.py i[…]
Using the Arduino IDE, you'll learn how to set up […]
In this project, you will post to Twitter using an[…]
In this project, we will build a water level contr[…]
I guess I'm late, but I had the same problem and f[…]
Last night I received my first D1 Minis for a lear[…]
Although I am aware that this is an old post, I fe[…]