Hi guys,
I have created a sketch that uses the ethernet module from the ESP.
Everything is working fine until I've added the pinMode function, which seems to be breaking the ethernet module from working.
when I remove the pinMode part it's back to work as expected,
The pin I have chooses to use are
#define GREENLED 19 // POWER LED
#define YELLOWLED 18 // SCALE LED
#define BLUELED 16 // ETHERNET LED
According to WT32-ETH01 sheets those pin are not in used at all:
BTW: I didn't even connect the LED to the esp.
This is my code:
#include <Arduino.h>
//#include <WiFi.h>
#include <WebSocketsClient.h>
#include "StompClient.h"
#include <ArduinoJson.h>
#include <SoftwareSerial.h>
#include <WebServer_WT32_ETH01.h>
#define DEBUG_ETHERNET_WEBSERVER_PORT Serial
#define GREENLED 19 // POWER LED
#define YELLOWLED 18 // SCALE LED
#define BLUELED 16 // ETHERNET LED
// Debug Level from 0 to 4
#define _ETHERNET_WEBSERVER_LOGLEVEL_ 0
/**
* Ethernet settings
*/
// Select the IP address according to your local network
IPAddress myIP(192, 168, 1, 232);
IPAddress myGW(192, 168, 1, 1);
IPAddress mySN(255, 255, 255, 0);
// Google DNS Server IP
IPAddress myDNS(8, 8, 8, 8);
/**
* Stomp server settings
**/
bool useWSS = false;
const char* ws_host = "192.168.1.50";
const int ws_port = 8080;
const char* ws_baseurl = "/stomp/"; // don't forget leading and trailing "/" !!!
char* deviceId = "A1B2C3D4";
char* subscribeDestination = "/subscriber/";
char* sendDestination = "/api/v1/sendmessage/";
// VARIABLES
String inString = "";
float weight;
WebSocketsClient webSocket;
SoftwareSerial myPort;
Stomp::StompClient stomper(webSocket, ws_host, ws_port, ws_baseurl, true);
boolean getScaleSample = false;
// Once the Stomp connection has been made, subscribe to a topic
void subscribe(Stomp::StompCommand cmd) {
Serial.println("Connected to STOMP broker");
stomper.subscribe(concatinateString(subscribeDestination, deviceId), Stomp::CLIENT, handleResponse);
sendMessage(concatinateString(deviceId," is logged!"));
}
void error(const Stomp::StompCommand cmd) {
Serial.println("ERROR: " + cmd.body);
}
Stomp::Stomp_Ack_t handleResponse(const Stomp::StompCommand cmd) {
//**
return Stomp::CONTINUE;
}
void sendMessage(String message) {
stomper.sendMessage(concatinateString(sendDestination, deviceId), message);
}
char* concatinateString(char* str1, char* str2) {
char *buffer = (char*)malloc(strlen(str1) + strlen(str2)+1);
sprintf(buffer, "%s%s", str1, str2);
return buffer;
}
void setup() {
Serial.begin(115200);
Serial.print("\nStarting BasicHttpClient on " + String(ARDUINO_BOARD));
Serial.println(" with " + String(SHIELD_TYPE));
Serial.println(WEBSERVER_WT32_ETH01_VERSION);
// To be called before ETH.begin()
WT32_ETH01_onEvent();
ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER);
ETH.config(myIP, myGW, mySN, myDNS);
WT32_ETH01_waitForConnect();
Serial.print(F("HTTP EthernetWebServer is @ IP : "));
Serial.println(ETH.localIP());
pinMode(BLUELED, OUTPUT);
pinMode(GREENLED, OUTPUT);
pinMode(YELLOWLED, OUTPUT);
digitalWrite(GREENLED, LOW);
digitalWrite(BLUELED, LOW);
digitalWrite(YELLOWLED, LOW);
myPort.begin(9600, SWSERIAL_8N1, MYPORT_RX, MYPORT_TX, false);
if (!myPort) { // If the object did not initialize, then its configuration is invalid
Serial.println("Invalid SoftwareSerial pin configuration, check config");
while (1) { // Don't continue with invalid configuration
delay (1000);
}
}
// Start the StompClient
stomper.onConnect(subscribe);
stomper.onError(error);
if (useWSS) {
stomper.beginSSL();
} else {
stomper.begin();
}
}
void loop() {
webSocket.loop();
/*if (WT32_ETH01_isConnected()){
if(digitalRead(BLUELED != LOW)){
digitalWrite(BLUELED, LOW);
}
}else{
if(digitalRead(BLUELED != HIGH)){
digitalWrite(BLUELED, HIGH);
}
}*/
if(myPort.available() > 0){
int inChar = myPort.read();
//digitalWrite(BLUELED, inChar);
if(inChar != '\n'){
inString += (char)inChar;
}else{
inString.remove(0,2);
weight = inString.toFloat();
if(getScaleSample){
sendMessage((String) weight);
getScaleSample = false;
}
inString = "";
}
}
}
Does anyone have any idea why the pinMode function breaks it?
Thanks!