I have a esp32 set up as a wifi device that sends Wind data from a davis 6410 to openplotter via port 10110.
I want write a routine that polls openplotter for a message to change the pin state on the esp32.
Remote control of light or lights attached to the ESP32.
In my old system I sent a message to a nano when I used a switch to set a pin high on the RPI.
This required python code to send and request data on the RPI. The nano, then base on this would set the pin High and turn the light on. I used NRF24l to transmit data.
The new system uses wifi and writes to the openplotter port directly. I don't need any code to run on the openplotter side.
My options are:
1. have the esp32 use mqqt.
2. python code to send current switch setting from pi
3. Use openplotter GPIO and have the ESP32 read the signalK value from the SignalK server.
4. Suggestions?????
Get state updates from SK server via WebSocket connection and retrieve initial state when the ESP acquires wifi connection via rest.
Sent from my iPhone using Tapatalk
Mqtt sent from node red dashboard works for me, with data getting sent back from the esp to get displayed in a node red dash text box if you want.
Sent from my SM-T813 using Tapatalk
Yaaa! little led on esp32 goes on and off When I use the switch on the RPI.
I went with option 3
I used API over stream as I wanted to get in and out fast, I don't know if it was faster?
I have the Davis anemometer outputting mnea @10hz to port 10110.
every second I get the value of Sensor.anchorlight via http/get.
then change the state of the pin on the esp32 to match.
It might be better to save the reading to a variable then just change pin if the value has changed.
Hey in the Openplotter GPIO tab I could not set the key to a sK spec key?
I could just get Sensor.* It would be nice if i could map to sK spec if it had a source that fit the use. For example
Lights
Thanks to
tkurki for that nice light read
For the most part mission success.
I can read/write winddata and control a light on a esp32 with no extra python code on RPI with openplotter via WiFi.
Well after some more testing I have an issue?
When the device is powered via USB it will run for days.
But when i use 12V power it crashes after about 12 hrs.
I checked the power supply, buck converter all seem well in spec range.
I turned debug on in the Arduino IDE and I am getting this error. every time i use the getLight function.
setting the timeout has no effect.
Code:
[E][WiFiClient.cpp:236] setSocketOption(): 1006 : 9
0x1006 is defined as
Code:
#define SO_RCVTIMEO 0x1006 /* receive timeout */
I dont know if this is my issue but it is the only error coming out of Debug.
The request is working and i get data back.
Here is the code i use.
Code:
void getlight()
{
uint16_t time = millis();
static uint16_t last_time;
uint16_t dt = time - last_time;
if (dt >= 1000) { // output every 1s
last_time += 1000;
if ((WiFi.status() == WL_CONNECTED)) { //Check the current connection status
HTTPClient http;
//http.setTimeout(10000);
http.begin("http://192.168.1.7:3000/signalk/v1/api/vessels/self/sensors/anchorLight"); //Specify the URL
int httpCode = http.GET();
//Make the request
if (httpCode > 0) { //Check for the returning code
String payload = http.getString();
StaticJsonBuffer<500> jsonBuffer;
JsonObject& root = jsonBuffer.parseObject(payload);
int code = root["value"];
http.end(); //Free the resources
if (code == 1) {
digitalWrite (ALT_PIN, HIGH); // turn on the LED
} else if (code == 0) {
digitalWrite (ALT_PIN, LOW); // turn off the LED
} else {
Serial.println("Fail");
}
return;
} else {
Serial.println("get http failed");
}
} else {
Serial.println("Error on HTTP request");
}
}
}
Good news no error in my code but issue with the Lib.
Thanks I will read though more a bit later...
LOL no "Problems" My last project used a NFR24 after the update to sketch my radio went nuts.. Several days later of debugging i realized that they had change the speed of the SPI bus. One line in my lib for the radio fix it. I am a bit worried about getting a reliable signal with the esp32.
WiFi seems a bit more robust than nrf24.. My biggest issue is the last time i did much c coding was in the Windows 3.1 era...
So I have the light going on and off via a switch to a gpio pin.
and the anchor/windspeed device updates SignalK Navigation/lights is changed to reflect this.
Code:
RPI WiFi ESP32
Pin high/low -------> Reads signalK PinState "Sensor.light.value" from GPIO tab
if the state has changed do the deed
Sets local Pin to match
<----- Sends SignalK update navigation/lights/Off or Anchored.
Should SignalK be change just to Anchored as Off is not really the right value if i have other lights in the future. Can I set lights to a Null if anchored is off?
Would it not be better just to have a array of bits that i could set the anchor bit on or off?
is this Stupid as lights is a enum and can only be a one of the values.
I never used Openplotter Actions but this would be easier.
How do you use Openplotter Actions? I cant seem to make it work?
I would not have to send the SK update if i could get to work
What is up with source vs $source..
If i use source... SK sees the source but openplotter does not show it in diagnostic.
But if i set $source SK reports no source but displays the SKKey and Diagnostic sees the Key.