Forum Replies Created
-
AuthorPosts
-
I will check with the power level. My assumption was that I could send SDI 12 commands and wiper runs, therefore Mayfly was able to provide those voltage.
I have tried the sensor with three other mayfly logger and among two SDI-12 D4-7, only one of each logger is able to make this wiper run.
One thing is I tried running mayfly with “?!” command but it get no response. I know the command is working because when i do “aM!” where a is the address (in my case 1M!) which means wipe and measure, the wipe happens but the command doesn’t give back any ack nor does it give response after waiting for while for the measured data.
Last week, i changed address to 1 and somehow it worked for a while but now it’s not working.The page says 12V is the default and my sensor is getting 12V because I could send command to run wiper which needs 12V and it works. But data measurement command doesn’t work.
I am using Mayfly v1.1. The turbidity sensor is connected with Screw Terminal.
I downloaded the zip from EnviroDIY_SDI12 using https://github.com/EnviroDIY/Arduino-SDI-12/archive/master.zip.
I am able to run the wiper with these:123Serial.println("Sending 0M2!");mySDI12.sendCommand("0M2!");delay(1000);Using this inside loop that runs every 30 seconds push the wiper. But, sending command to get data results in nothing.
while (mySDI12.available()) { Serial.write(mySDI12.read()); } This mySDI12.read() return nothing. I checked and see that all the wires are connected properly.
How do I do this? “set the jumper header next to the Grove jack to the 12v jumper setting? “. If my wiper which needs 12V is running well, doesn’t that mean it’s on 12V setting?Thank you so much.
I am not using the AWS stuff for now but I will be deploying mosquitto on cloud at some time.
if this old firmware create problem at that point, I will update the firmware.
Thank you again.I am using EnviroDIY fork. Until now everything is working. I am able to make both http post, and mqtt connection.
I checked and mine esp32 firmware version is 2.4.0. So,Is it because of this lower version, I had to do some hack around for ssl connection?
Below is the part of workaround I coded to make it work with hydroserver.1234567891011121314151617void ExpressifESP32::extraSetupForHTTPS(const char* host, const int port) {// Some HTTPS servers(like playground instance of hydroserver) host multiple domains on the same IP address.// During the TLS handshake, the modem must send the hostname using// Server Name Indication so the server can present the correct// SSL/TLS certificate. Without SNI, the connection may fail even// though DNS resolution and TCP connectivity succeed._modem.sendAT(GF("+CIPRECVMODE=1"));// Ref: https://docs.espressif.com/projects/esp-at/en/release-v2.4.0.0/esp32/AT_Command_Set/TCP-IP_AT_Commands.html#at-cipsslcsni-query-set-ssl-client-server-name-indication-sni_modem.sendAT(GF("+CIPSSLCSNI=0,\""), host, GF("\""));_modem.sendAT(GF("+CIPSSLCSNI=1,\""), host, GF("\""));delay(3000);// See : https://docs.espressif.com/projects/esp-at/en/latest/esp32/AT_Command_Set/TCP-IP_AT_Commands.html#cmd-start// same as above. This also need to be done twice_modem.sendAT(GF("+CIPSTART=0,\"SSL\",\""), host, GF("\","), port);_modem.sendAT(GF("+CIPSTART=1,\"SSL\",\""), host, GF("\","), port);}I have.
Before opening a tcp connection, the Socket Receiving Mode should be made to 1 (passive mode). I have no idea why it works only while doing this. But it works.12345void ExpressifESP32::extraSetupForMQTT(){// See :https://docs.espressif.com/projects/esp-at/en/release-v2.4.0.0/esp32/AT_Command_Set/TCP-IP_AT_Commands.html#at-ciprecvmode-query-set-socket-receiving-mode// This should be done before opening tcp connection_modem.sendAT(GF("+CIPRECVMODE=1"));}I found the modularsensor implementation difficult. Therefore wrote my own small class that wraps tinygsm for the functions that I need.
One thing I found is modemBaud is 57600 which is different from the comments in the esp class
Never mind. The wifi worked. I used
AT+CWMODE?and change it from SoftAP to Station mode.
But I am struggling to use this to connect to mqtt broker.Thanks for the reply.
So, how do I even do POST request to server running on the web? Are there any Wifi modules that are alternative to Xbee that supports SecureClient?Thank you for your response.
I used TinyGSM directly and got into this problem. I was deploying broker locally,, the code on the inside check for dns lookup.. Currently I commented this code out and tinygsm works.
https://github.com/issues/created?issue=vshymanskyy%7CTinyGSM%7C854This is what my full code looks without tinygsm:
C++123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131#define XBEE_PWR 18#define XBEE_SERIAL Serial1#include <ModularSensors.h>#include <modems/DigiXBeeWifi.h>#include <ArduinoMqttClient.h>// the broker id doesn't matter as client is already connected to that ip with xctuconst char broker[] = "asdasd";const int port = 1883;const char* mqttClientID = "MayflyXBee";const int8_t powerPin = 18;const int8_t statusPin = 19;const int8_t modemResetPin = 20;const int8_t modemSleepRqPin = 23;const char* ssid = "USU-guest";const char* pwd = "";DigiXBeeWifi modemXBWF(&Serial1, powerPin, statusPin, false,modemResetPin, modemSleepRqPin,ssid, pwd, false);class XBeeTransparentClient : public Client {public:XBeeTransparentClient(Stream& s) : _stream(s) {}int connect(IPAddress ip, uint16_t port) override { return 1; }int connect(const char* host, uint16_t port) override { return 1; }void stop() override {}uint8_t connected() override { return 1; }operator bool() override { return true; }size_t write(uint8_t b) override { return _stream.write(b); }size_t write(const uint8_t* buf, size_t size) override { return _stream.write(buf, size); }int available() override { return _stream.available(); }int read() override { return _stream.read(); }int read(uint8_t* buf, size_t size) override { return _stream.readBytes(buf, size); }int peek() override { return _stream.peek(); }void flush() override {}private:Stream& _stream;};XBeeTransparentClient xbeeClient(Serial1);MqttClient mqttClient(xbeeClient);void setup() {Serial.begin(9600);pinMode(XBEE_PWR, OUTPUT);digitalWrite(XBEE_PWR, HIGH);delay(2000);XBEE_SERIAL.begin(9600);if (!checkForConnection()) {Serial.println("Could not connect to WiFi");return;}Serial.println("WiFi connected!");delay(5000);mqttClient.setId(mqttClientID);Serial.println("starting mqtt");if (!mqttClient.connect(broker, port)) {Serial.print("MQTT failed, error: ");Serial.println(mqttClient.connectError());} else {Serial.println("MQTT connected!");}}void loop() {if (!mqttClient.connected()) {Serial.println("MQTT disconnected, reconnecting...");delay(3000);mqttClient.connect(broker, port);return;}mqttClient.poll();mqttClient.beginMessage("sensors/data");mqttClient.print("temperature=23.5");mqttClient.endMessage();Serial.println("Message sent");delay(2000);}bool checkForConnection() {String status = "F";int attempts = 0;XBEE_SERIAL.print("+++");delay(1100);clearXbeeSerialBuffer();while (status != "0" && attempts < 50) {XBEE_SERIAL.println("ATAI");delay(500);if (XBEE_SERIAL.available()) {String response = XBEE_SERIAL.readStringUntil('\n');response.trim();status = response;}attempts++;Serial.println(status);delay(1000);}XBEE_SERIAL.println("ATCN");delay(3000);clearXbeeSerialBuffer();delay(2000);return status == "0";}void clearXbeeSerialBuffer() {while (XBEE_SERIAL.available()) {XBEE_SERIAL.read();}}This is how I am implementing tinygsm
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192// this is the working code// but the mqtt connection closes immediately after first time// need to figure out the reason#define TINY_GSM_MODEM_XBEE#define TINY_GSM_RX_BUFFER 256#define TINY_GSM_USE_GPRS false#define TINY_GSM_USE_WIFI true#define TINY_GSM_DEBUG Serial#include <Arduino.h>#include <TinyGsmClient.h>#include <ArduinoMqttClient.h>#include <StreamDebugger.h>#define SerialMon Serial#define SerialAT Serial1#define XBEE_PWR 18const char* broker = "raspberrypi1.mypc.usu.edu";const int port = 1883;const char* topicTemp = "sensor/temperature";StreamDebugger debugger(SerialAT, SerialMon);TinyGsm modem(debugger);TinyGsmClient client(modem);MqttClient mqtt(client);void setup() {SerialMon.begin(9600);delay(20);pinMode(XBEE_PWR, OUTPUT);digitalWrite(XBEE_PWR, HIGH);delay(2000);SerialAT.begin(9600);delay(3000);SerialMon.println("Waiting for WiFi...");delay(5000);SerialMon.print("Local IP: ");SerialMon.println(modem.localIP());mqtt.setId("ArduinoTempSensor");mqtt.setTxPayloadSize(512);SerialMon.print("Connecting to MQTT broker: ");SerialMon.println(broker);if (!mqtt.connect(broker, port)) {SerialMon.print("MQTT connection failed, error code: ");SerialMon.println(mqtt.connectError());} else {SerialMon.println("MQTT connected!");}}void loop() {// Reconnect if droppedif (!mqtt.connected()) {SerialMon.print("MQTT disconnected, reconnecting... ");delay(1000);if (!mqtt.connect(broker, port)) {SerialMon.print("failed, error code: ");SerialMon.println(mqtt.connectError());delay(5000);return;}SerialMon.println("reconnected!");}mqtt.poll();// Publish temperature every 10 secondsstatic unsigned long lastMsg = 0;if (millis() - lastMsg > 10000L) {lastMsg = millis();float temperature = 20.0 + random(0, 150) / 10.0;SerialMon.println();SerialMon.print("This is the console output Publishing temperature: ");SerialMon.println(temperature);SerialMon.println();mqtt.beginMessage(topicTemp);mqtt.print(temperature);mqtt.endMessage();}}Tinygsm implementation will result in flaky broker connection like this:
1773954855: New client connected from 144.39.141.49:49164 as ArduinoTempSensor (p4, c1, k15). 1773954865: Client ArduinoTempSensor [144.39.141.49:49164] disconnected: connection closed by client. 1773954865: New connection from 144.39.141.49:49165 on port 1883. 1773954865: Protocol error from 144.39.141.49:49165: First packet not CONNECT (30). 1773954865: Client 144.39.141.49 [144.39.141.49:49165] disconnected: protocol error.Thank you for your response.
I think it’s the master branch.Also, this is what I am trying to do.
DigiXBeeWifi modemXBWF(&Serial1, powerPin, statusPin, false,
modemResetPin, modemSleepRqPin,
ssid, pwd, false);Client* netClient = nullptr;
MqttClient* mqttClient = nullptr;void setup() {
Serial.begin(9600);
Serial1.begin(9600);
delay(2000);if (!modemXBWF.connectInternet(60000L)) {
Serial.println(“WiFi failed!”);
return;
}
Serial.println(“WiFi connected!”);delay(1200);
netClient = modemXBWF.createClient();
mqttClient = new MqttClient(*netClient);<div>Somehow this code is called. bool DigiXBeeWifi::extraModemSetup(void). I don’t know which line does this. So the broker connection fails.
I have used this workaround by implementing the Client with just a fake abstract wrapper and preconnect xbee s6b with xctu…
class XBeeTransparentClient : public Client {
public:
XBeeTransparentClient(Stream& s) : _stream(s) {}int connect(IPAddress ip, uint16_t port) override { return 1; }
int connect(const char* host, uint16_t port) override { return 1; }
void stop() override {}
uint8_t connected() override { return 1; }
operator bool() override { return true; }size_t write(uint8_t b) override { return _stream.write(b); }
size_t write(const uint8_t* buf, size_t size) override { return _stream.write(buf, size); }
int available() override { return _stream.available(); }
int read() override { return _stream.read(); }
int read(uint8_t* buf, size_t size) override { return _stream.readBytes(buf, size); }
int peek() override { return _stream.peek(); }
void flush() override {}private:
Stream& _stream;
};</div>
-
AuthorPosts
Welcome to EnviroDIY, a community for do-it-yourself environmental science and monitoring. EnviroDIY is part of