How to send messages to IoT Gateway with server running on Google Linux instance - google-cloud-iot

I am trying to send messages from my mac to a Google IoT Gateway running on a Google VM linux instance. Can't get the gateway server running in the linux instance to ack messages sent from scripts on my mac.
Set up Google VM linux instance and followed directions in:
https://codelabs.developers.google.com/codelabs/cloud-iot-core-gateways/index.html#0
I did try to read through https://cloud.google.com/community/tutorials/cloud-iot-gateways-rpi.
I setup GOOGLE_CLOUD_PROJECT to point to my project.
I updated the ADDR in the thermostat.py script to point to the address of the linux instance. But I am not quite sure which address to use.
The address obtained by running ifconfig on the linux instance isn't pingable from my mac. I used the static address assigned to the linux instance, and although I can ping that, I don't see the server running on the gateway ack the message send by the script.
On the linux instance I run the gateway server, and if I run thermostat.py on the same instance, I see the messages received by the gateway and the Google IoT console.
However I am having trouble running thermostat.py from my local machine (mac). I want to get this working before trying it on my embedded device. I can see the script attempt to send the message but I don't see any messages received on the server.
Which ip address should I be using to communicate with the gateway server on my linux instance ?
Other than setting the ADDR and GOOGLE_CLOUD_PROJECT, are there any other changes I need to make to thermostat.py?

The VMs in GCE (Google Compute Engine) have a locked down firewall by default. You need to open up the ports for the HTTP connection so the traffic to the gateway can get through.

Related

How to connect a Server in linux (host) with a client running in QEmu's guest linux (guest)

I want to connect via TCP socket a server app running in the host with a client running in the QEmu guest.
I use port 5104 for the socket in the server.
I start the server.
Then I found that I can not launch the QEmu giving that port as the input point for the client in the guest, like this:
qemu-system-arm ... -net user,hostfwd=tcp:127.0.0.1:5104-:5104
Gives the error "Could not setup host forwarding rule ..."
I guess that qemu acts like a server also and then the port is already taken by the server previously launched and then is not possible to do it.
Which is the correct syntax? The documentation talks about the option guestfwd but I tried all the possibilities and I couldn't found the solution. It should be way to do it.
Any suggestion?

Can ssh to GCP Private instance but cant access application interface through cloud shell

Here is what i have:
GCP instance without external IP (on VPC, and NAT), and it accepts HTTP HTTPS requests
firewall allows ingress TCP for 0.0.0.0 and also for IAP's IP 35.235.240.0/20 on all ports for all instances
I ssh to the instance via IAP and run the application in the terminal on port 5000 and 0.0.0.0 host and leave the terminal hanging, but when I connect in parallel through cloud shell and ssh to this instance through IAP, and then click on web preview on port 5000, I get "Couldn't connect to a server on port 5000".
I have said that it could be a firewall rule blocking IAP, so that's why I gave access to all ports for IAP (for testing)
P.S: the process has been done on a VM with external IP and it got validated ( but without the need to connect to cloud shell to do web preview, I checked the UI with IP:port in the browser )
What did I miss?
You may be following the guide on Building Internet Connectivity for private VMs and this part on Configuring IAP tunnels for interacting with instances and the use of TCP Forwarding in IAP. By Tunneling other TCP connections:
"The local port tunnels data traffic from the local machine to the remote machine in an HTTPS stream. IAP then receives the data, applies access controls, and forwards the unwrapped data to the remote port."
You can create an encrypted tunnel to a port of the VM instance by:
gcloud compute start-iap-tunnel INSTANCE_NAME INSTANCE_PORT \
--local-host-port=localhost:LOCAL_PORT \
--zone=ZONE
I guess you want to use INSTACE_PORT and LOCAL_PORT the same, 5000.
Be aware of it's known limitations.

SIM5320A, device connected to 3G Network but can't ping server

I've been trying to make this SIM5320A module send HTTP requests to my server but even though it appears connected to the internet I can't seem to ping any server or make any requests.
I'm sending AT commands through a terminal on my Linux PC.
AT+CPIN appears READY
I've configured through the AT+CGDCONT, AT+SOCKSETPN = 1 and AT+CGSOCKCONT commands, adding my service provider's APN.
AT+NETOPEN returns OK. Running it again returns Network is already opened.
AT+CPSI? show's that it's connected to the WCDMA network and is online.
AT+IPADDR throws a proper IPv4 address.
So I'm trying to do AT+CPING="google.com",1 but it just won't connect.
I've even been able of sending a SMS and reading GPS coordinates, just failing in the internet stuff.
Am I missing any configuration steps? There is so little information online on this device.

Cannot access chef-server web interface. (No route to host)

I have got chef-server installed on a centos machine.
Everything is working as expected except that I cannot access the chef-server web interface from another machine on my local network.
I can access the web interface from the centos machine itself:
telnet mychefserver.local 4000
Connected
If I do the same from my machine I have got:
telnet: Unable to connect to remote host: No route to host
I can successfully ping mychefserver.local from my machine
Any idea how to configure nginx with chef-server to access the chef-server from the network?
Since Chef Server 10, the web interface uses normal HTTPS (TCP 443), it only listens on the high ports locally, and nginx proxies as needed to the different backend services. I would try with a normal web browser as telnet isn't exactly great at error messages. Normally I would expect that to mean telnet is getting TCP transmission errors, but maybe it is just confused? If it is really a TCP transmit error then more likely the internal DNS is having issues. .local often means mDNS which has uneven support in some places, I would try an actual IP address to be sure.
My issue was iptables.
I stopped iptables and I can access the chef-server from my local network again.

Send HTTP POST to API server running on localhost from another PC

My web server is running on localhost (127.0.0.1:8800) and I would like to send HTTP posts from another machine to that server.
Does anyone know how I will be able to access the server from the outside? (I did a SSL port forwarding from the external address to localhost, but it is a kind of hack and some aspects do not working properly, e.g. web socket does not detect traffic that's been forwarded)
127.0.0.1 is the loopback address of your network card. Only your computer can access that. 127.0.0.1 on any other computer will be that other computer.
You will have to run your server on your internal ip-address (if you're doing this in an internal network). It will probably look something like 192.168.0.x. If you're instead connecting to the computer using the internet you will of course have to bind the server to the external ip-address.
You can find your internal ip-address on Windows by opening cmd.exe and typing ipconfig. On OSX or Linux/BSD you run ifconfig in a terminal.

Resources