-2

I need a simple way of sending a string from my raspberry pi to my laptop (on the same WiFi network) and then store in a Sqlite database.

arush436
  • 1,748
  • 20
  • 20
  • What technology do you want to use? If you know what technology you want you should find examples on the internet. If you want a recommendation for a technology this is probably the wrong place to ask. – Joelius Jun 16 '19 at 11:59
  • A database server that works over a network, like Postgresql or MariaDB, is a better choice than sqlite for this usage. – Shawn Jun 16 '19 at 12:07
  • You can simply send and receive strings with `netcat` also known as `nc`. – Mark Setchell Jun 16 '19 at 12:11

1 Answers1

1

The most basic way could be through socket programming :

Code on raspberrypi :

import socket                

s = socket.socket()          

port = 12345                

s.connect(('<your_ip_address>', port)) 

s.send('Hello this is your rpi') 

s.close() 

Code on your laptop :

import socket                

s = socket.socket()          
print "Socket successfully created"

port = 12345                

s.bind(('<your_ip_address>', port))         
print "socket binded to %s" %(port) 

s.listen(5)      
print "socket is listening"            

while True: 

   c, addr = s.accept()      
   print 'Got connection from', addr 

   c.send('Thank you for connecting') 

   c.close() 

Another way could be through mqtt where you will have to set up an mqtt server on the pi and a client on the laptop, the raspberrypi would then send messages over a specific topic which the client (laptop) can subscribe to and keep listening to it till a message is received.

You can refer to python mqtt script on raspberry pi to send and receive messages for the same

Amartya Gaur
  • 665
  • 6
  • 21