0

I'm a beginner with Raspi and I would appreciate your advice and input on a project I'm working on.

Hardware: Raspi 3B+ with latest Rasbian, Arduino MKR 1000

I have a bunch of sensors attached to the Raspi(Ultrasonic and IMU) and I want to pass data from the Raspi to the MKR1000 with Raspi acting like server and Arduino like a client. They will be connected to the same network through Wi-Fi. I want to know if this is possible and what is the most easiest way to do this? Also, I was advised that writing a socket would be helpful with the problem but I have no clue how to write a socket for Arduino that can interact with the Pi, I already have a socket server program that I use for Pi(Code below), would this program be capable of sending strings to the Arduino? Any resources, videos, sample code would be appreciated. Thank you for your time.

import socket
import sys

    HOST = '192.168.130.206'    #Ip the server is run on
    PORT = 50007              # Arbitrary non-privileged port
    s = None
    for res in socket.getaddrinfo(HOST, PORT, socket.AF_UNSPEC,
                                  socket.SOCK_STREAM, 0, socket.AI_PASSIVE):
        af, socktype, proto, canonname, sa = res
        try:
            s = socket.socket(af, socktype, proto)
        except OSError as msg:
            s = None
            continue
        try:
            s.bind(sa)
            s.listen(1)
        except OSError as msg:
            s.close()
            s = None
            continue
        break
    if s is None:
        print('could not open socket')
        sys.exit(1)
    conn, addr = s.accept()
    with conn:
        print('Connected by', addr)
        while True:
            data = conn.recv(1024)
            if not data: break
            conn.send(data)
    enter code here
  • Ask Arduino questions on arduino.stackexchange.com/questions – Milliways Jan 16 at 0:35
  • But the question is focused on Raspi as well though? I dont know if the Pi is capable of acting like a server and if it is possible for the Pi to communicate with the Arduino through sockets. Should this be a Arduino question instead? – LeafTeaNeko Jan 16 at 0:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.