Hi community,
I am struggling to build a communication bridge between Arduino and Python. Below is my code:
#include <mcp_can.h>
#include <SPI.h>
#include <SD.h>
#include <Ethernet2.h>
#include <EthernetUdp2.h> // UDP library from: bjoern@cs.stanford.edu 12/30/2008
byte mac[] = {
0xA8, 0x61, 0x0A, 0xAE, 0x2A, 0x12
};
IPAddress ip(127.0.0.1);
unsigned int localPort = 8880; // local port to listen on
// An EthernetUDP instance to let us send and receive packets over UDP
EthernetUDP Udp;
void setup()
{
Ethernet.begin(mac, ip);
Udp.begin(localPort);
Serial.begin(115200);
}
void loop()
{
char ReplyBuffer[] = "acknowledged";
Udp.beginPacket(ip, localPort);
Udp.write(ReplyBuffer);
Udp.endPacket();
}
Below is the python code:
import serial
import time
import socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind(('127.0.0.1', 8880))
data, addr = sock.recvfrom(1024) # buffer size is 1024 bytes
sock.close()
I am getting suspicious of this ip adress '127.0.0.1' that I am sending the data to. If this is not the right adress, which one should I use?