Is there anyway to send data through RPi and the Mac OS X wirelessly? - websocket

I am trying to build a robot that captures images from the RPi camera that is in installed, and try to sent it over to my Mac to do the image recognition and sent the result back. The robot was controlled by the Raspberry Pi 3 Model B. I have tried to communicate through socket but the whenever the it tries to connect, it always says “Connection refused” Any suggestions on new ways to communicate the RPi and the Mac wirelessly?
This is the code for the Server:
import socket
server = socket.socket()
server.bind(('127.0.0.1', 8000))
server.listen(0)
connection = server.accept()[0].makefile('wb')
print("success")
This is the code for the Client:
import socket
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect(('127.0.0.1', 8000))
connection = client.makefile('rb')
print('connection sucessful')
Remember: I am just trying to make sure that the connection between the Raspberry Pi and the Mac is successful.

I just figure it out. I just noticed that before I even connect, I am already connected to the RPi using SSH. I was using this so I could edit the code of the RPi. So what I did is that I connected the RPi to a different device, and then run the server code on the Mac, and the client on the RPi. It was a success.
Sorry if you were having a hard time answering my question. After all, it was just a mistake noticing the SSH connection.

Related

How to read files from a SD card connected to ESP32 an then transfer/upload/send them with Micropython to Raspberry Pi?

I am working on a project, basically my proposal consist in a solution designed under server/client paradigm, on host side I have mounted an Ubuntu Server 20.4 LTS (64 Bits) on a raspberry pi and setup Flask (1.1.1) as a restful web service, on the other side I have the ESP32 with Micropython (v1.19.1) as a client that is sending data thru http to the web API.
So far so good, but I am planning on keeping log files as back up on the SD card connected to ESP32 for down time communication scenarios between server and client, since the down time period could be from a few hours to a whole day, I was thinking on keeping data in raw format in files generated by the hour in text plain, then eventually whenever the connection gets stablished the ESP32 can send files to server, so data can be parsed and do whatever was missing on the flow.
I also know that I could do the data parsing on client side and send a bunch of request to the Web API but giving the condition that the down time can last for several hours this could affect the performance of the main task on the ESP32 which is to collect data from sensors and prepare it to be sent to the raspberry pi.
What have I tried so far?, well I already have the code to read files from a SD card with ESP32 but due to the constraints on Micropython I am not able to send them thru http since the urequests library does not support it, despite that Flask on server side can handle it without problem.
import urequests
from machine import Pin, SPI
import machine, sdcard, os
spi = SPI(1, baudrate=10000000, polarity=0, phase=0,
miso=Pin(13),
mosi=Pin(12),
sck=Pin(14))
sd = sdcard.SDCard(spi, Pin(27))
os.mount(sd, '/sd')
files = [
('20220510_08', open('/sd/20220510/20220510_08.csv','csv')),
('20220510_09', open('/sd/20220510/20220510_09.csv','csv'))
]
payload = {}
headers = {'Content-Type': 'multipart/form-data'}
host = "http://192.168.0.25:5000/uploadLogFile"
response = urequests.request("POST",url = host, headers=headers,files = files)
TypeError: unexpected keyword argument 'files'
I was also thinking on setting up the FTP service on the raspberry pi, and look for a FTP client for the ESP32 in Micropython, so files can be transfer.
I think in theory makes sense but I wonder if anyone else has made something similar and have a code sample to share or either if someone has any better recommendation, since I am still new to Micropython programming I might be missing sight of something else worth of reviewing .
I thank you all in advance.
Regards

From WiFi to Cellular 3/4G on ESP32

I am building a project utilizing Wifi on the ESP32 module. Using RTOS, I am running a web server on 1 core and a web client on another core. This works very well and I can access the web server remotely via my browser and the WiFi provided IP address. The Web client reads some sensors and sends the data via WiFi to my database. All good and everything works as desired.
Now I need to do the next step and move beyond the reach of the WiFi and reproduce the same result via 3/4G cellular. I looked at the "easy" solution to use an industrial 3/4G WiFi router and simply keep what I have. Cost of these "industrial" type routers are on the high side, where as 3/4G module which also include a GPS chip are around half or less. Problem is that I cannot get my head around how I will "replace" my current WiFi functionality with one of these modules. The modules seems to expect you to connect via serial (rs232) and using modem AT commands establish a connection to the internet. Question is, after connecting to the internet, how do you continue to have "network functionality" same as with the built-in WiFi? Is there some library that will do ethernet over the serial port? Can I still have the WiFi and the "serial ethernet" running at the same time or switch between the two?
Thanks!

Initial Connection for network setup from Smartphone to raspberry

I have Raspberry Pi 3 model B
OS: Raspbian(jessie)
I want to create a connection from my smartphone to a headless raspberry, and connect the headless raspberry to a network(which the smartphone is conencted).
like the vacum cleaner robot (IRobot) or Web camera which has an app, or any device that needs an initial connection to setup it's network.
the initial connection needs to be from a remote device, mainly a smartphone app.
What did i try:
1. bluetooth - i've managed to setup the bluetooth in the raspberry. when i try to connect, a popup appears on the raspberry which ask to confirm connection, because the raspberrry needs to be headless, this option is not good for us.
if i set the bluetooth as follow: sudo hciconfig hci0 sspmode 0
when i try to connect to the raspberry, a popup appears in the smartphone required a PIN code, this option may be good, if i new the PIN code.
2. P2P - i try use wifi direct from my smartphone
i've create file called p2p.conf inside /etc/wap_supplicant
inside this file i wrote the following:
ctrl_interface/var/run/wpa_supplicant
update_config=1
device_name=raspberry
device_type=1-0050F204-1
driver_param=use_p2p_group_interface=1
p2p_go_intent=1
p2p_go_ht40=1
then stop the wpa_supplicant and change
sudo wpa_supplicant -B -iwlan0 -Dnl80211 -c/etc/p2p.conf
i've started wpa_cli
and then p2p_find
it's started scanning
when i search from the smartphone for the raspberry, i found the raspberry, when i try to conenct it asks me for PIN code, the PIN code is showen in the raspberry wpa_cli.
two problem i have from this option:
1. the network needs to be connected.
2. the PIN code changes, and i can't make it fixed.
Is there a way to make an initial connection to setup a network from the smartphone to a headless raspberry?

Tizen WebSockets: can access Internet WebSocket server but cannot acces LAN WebSocket server

last week I started to develop apps for a Samsung Smartwatch with the Tizen SDK 2.4.0. My sample web application connects to a remote Websocket server (a simple echo server) and sends some random requests and prints the received messages (Server is http://www.websocket.org/echo.html). This works fine on an emulated devices as well as on the real Gear S2 Smartwatch (Example was taken from https://developer.tizen.org/zh-hans/development/tutorials/web-application/w3chtml5supplementary-features/communication/websocket?langredirect=1)
But as soon as I start a Websocket server in my home LAN I run into problems. The server is launched via a simple Python example I found on Github (https://github.com/dpallot/simple-websocket-server). The emulator device from the SDK connects to this server without any problems using the local IPv4. But the real device, which is logged in to the same WiFi access point, doesn't.
Note that the connection between my PC and my watch device works fine, since the SDK flashes the developed apps via WiFi to the device.
In my config.xml all connections are allowed
<access origin="*" subdomains="true"></access>
and the privilege for "Internet" is available.
The logs show that the watch tries to open a connection, but is then stuck. No error message is printed - the watch just does not go beyond the initial creation of the websocket.
Do you have any hints or thoughts about how I could debug this issue?
Thanks in advance!
I found the solution - my virus scanner has an integrated software firewall that blocked incoming connections...
Try with higher ports maybe ? I got WS working fine on SamsungZ1 on Tizen:2.3:Mobile
https://twitter.com/RzrFreeFr/status/70135763074535014#tizen-gear2-websockets
Maybe I could try your code on Tizen:2.4:Mobile too ?

Setting up domain name redirection on Mac OSX for all! domains

im trying to setup a redirection towards an app that im writing in Java. This app opens a port 8443 on my laptop (which is a MacOS 10.10 Yosemite) and offers a HTTPS service.
The big plan is to have another device connecting to an access point that im setting up on my laptop and when it connects to any ip/domain on 443 this traffic is redirected to my local machine on port 8443.
I need to redirect traffic that im getting on 443 to 8443. I kinda might have gotten a solution for this using the following guide: http://www.abetobing.com/node/81, and changed the rule to rdr pass on lo0 inet proto tcp from any to any port 443 -> 127.0.0.1 port 8443
But this rule only works locally if im right about that. So only traffic coming from my own laptop is redirected. if im trying to open https://192.168.178.25/ on another machine it doesn't work, but https://192.168.178.25:8443/ does.
Additionally i also was able to change a domain via the /etc/hosts file. That only works for local connections and for single domains if im right. So the second step would be to redirect ALL possible domain names to my ip. I think this should be possible with kinda of a proxy service, but since i am new to this topic I haven't found a solution that is working for me.
At the moment I am using 2 Wifi devices and the MacOS Internet share. My USB wifi card is connected to a router and internet. My internal wifi card opens an access point (it says hotspot) and offers the internet connection of the other device. This is annoying, since the USB wifi connection always has to work, otherwise MacOS will shut down the access point. The best solution would be a software opening a reliable access point with the internal wifi card (haven't had any success with the Mac OS ad-hoc network)
I would be so glad if someone would be able to help me out with any of the 3 single parts. Thank you already :)

Resources