One end of the shield is connected to the lan port of the laptop and the other end of the shield is connected to the arduino board
SCK connected to 13,
SO connected to 12,
SI connected to 11,
CS connected to 10
One end of the shield is connected to the lan port of the laptop and the other end of the shield is connected to the arduino board
SCK connected to 13,
SO connected to 12,
SI connected to 11,
CS connected to 10
My knowledge of networks is limited but I suspect that is never going to work. Back in the Dark Ages when I used Ethernet directly between devices like that I used an Ethernet crossover cable because Ethernet is not designed to connect devices directly. See Ethernet crossover cable - Wikipedia
The normal way of connecting devices is to connect them each to a router
It is, however, worth trying to allocate the required local IP address in your sketch as later hardware may have circuitry to deal with the straight rather than crossed cables
This sketch show ip address on serial monitor
#include <UIPEthernet.h>
// Update these with values suitable for your network.
byte mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED };
byte ip[] = { 192, 168, 20, 19 };
EthernetClient ethClient;
void setup()
{
Serial.begin(9600);
Ethernet.begin(mac, ip);
Serial.println( Ethernet.localIP());
}
void loop()
{
}
But there is the problem of connection loss so I was trying new library
Unless/until you solve the problem of the physical Ethernet connection then MQTT is never going to work
How does your laptop connect to the Internet ?
I connect laptop to the internet from my mobile hotspot
so i am trying to fix ethernet connection first but without router it seems very difficult
The easiest thing to do would be to use a board such as the ESP32 that has built in WiFi but I realise that involves buying one
i agree with you
I heard that many people don't prefer wireless communication for security purpose. That's why i wanted to get some knowledge on ethernet communication by doing experiment.
Well, you certainly got some knowledge about Ethernet, but as you are already using WiFi what is the point ?
i don't have a router so i use my mobile hotspot to connect the laptop to the internet.
In this experiment I was not connecting my laptop to the internet I just connected the laptop LAN port to the one end of shield and the other end the shield to the Arduino board.
I just wanted to send the Mqtt data over Ethernet, not over Wi-Fi
That connection uses WiFi so maybe you should be concerned about that
Did you try setting the IP address of your shield explicitly ? There is a faint possibility that it might work without a crossed Ethernet cable but don't hold your breathe
In addition to the crossover cable, I'd guess that there is some configuration to do on the laptop to share its internet connection.
The MQTT broker is running on the laptop so Internet connectivity is not strictly needed
no it's not working
I want to send mqtt data over ethernet, so what do i need in hardware?
I have following
Board : Arduino Uno 3,
Ethernet : enc28j60
LAN Cable
Laptop
Apart from this, do I need anything else like a router?
If having a router can solve the problem then I will bring a router?
I don't have experience with this model but the model I have is it compatible with Arduino board
?
Could there be a problem with the libraries I'm using as well?
A router to which you connect both the laptop and the Arduino should work when used with regular Ethernet cables but you can buy crossed Ethernet cables very cheaply
Oops.
You probably don't need a full blown router for this - a simple switch should do the job.
I have no idea and could not tell from your picture anyway
What makes you think that it is a crossover cable ?
actually i have no idea but i used that cable to connect shield to laptop and i also received data successfully but getting connection loss problem
I tried at my friend's home, Connecting router to both devices solve the problem of connections
I tried this one sketch also but I didn't get array, What's wrong with this sketch ?
#include <UIPEthernet.h>
#include <PubSubClient.h>
int count = 0;
char input[13];
// Update these with values suitable for your network.
byte mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED };
byte server[] = { 192, 168, 120, 19 };
byte ip[] = { 192, 168, 120, 20 };
EthernetClient ethClient;
void callback(char* topic, byte* payload, unsigned int length);
PubSubClient client(server, 1883, callback, ethClient);
// Callback function
void callback(char* topic, byte* payload, unsigned int length) {
}
void setup()
{
Serial.begin(9600); // begin serial port with baud rate 9600bps
Serial1.begin(9600);
pinMode(led, OUTPUT);
digitalWrite(led, HIGH);
Ethernet.begin(mac, ip);
digitalWrite(led, LOW);
Serial.println( Ethernet.localIP());
if (client.connect(" ")) {
client.publish("output/system/", "ready");
client.subscribe("input", "1");
Serial.println("1");
digitalWrite(led, HIGH);
}
}
void loop()
{
client.loop();
if (Serial1.available())
{
if (Serial1.available() && count < 13) // Read 12 characters and store them in input array
{
input[count] = Serial1.read();
count++;
input[count] = '\0';
delay(5);
}
client.publish("system", input[count]);
if (count == 12) {
count = 0;
}
}
}
Why are you publishing each character of the ID as it is received ? The idea was to read characters from the tag until you had got all of them then publish the whole array
Back in reply #41 you used that principle at my suggestion and reported "It works"
Can you please explain this section of code
count2 = 0;
if ((Serial1.available() >= 13) && ( FLAG1 == false)){
input2[count2] = Serial1.read();
count2++;
input2[count2] = '\0';
Serial.println(input2);
We have declared array that will hold 13 characters of string including null terminated