LowPowerLab Forum

Software support => Pi Gateway => Topic started by: LukaQ on January 10, 2017, 04:34:55 AM

Title: Test Pi gateway serial without Moteino? [solved]
Post by: LukaQ on January 10, 2017, 04:34:55 AM
Hello,

I wanted to try gateway before I get anything else then PI3. What would be needed, to send, to serial of PI3 to get node in gateway to pop up and show data, make graph... even if data would be static all the time?

So in short:
PC > USB to serial > PI3 serial
to get node to show with some data (let say one would send water meter data)

what would that ASCII string look like on PI3 serial port?


Best regards, Luka
Title: Re: Test gateway (Pi) without Moteino?
Post by: Felix on January 10, 2017, 09:11:38 AM
Just send some sample data to the Pi's serial port (/dev/ttyAMA0 default, configurable in the settings page of the GUI), it doesn't have to come from a Moteino.
The acceptable metrics are defined as regular expressions in metrics.js (https://github.com/LowPowerLab/RaspberryPi-Gateway/blob/master/metrics.js).
A simple example is sending random temperature data: C:34.5 or F:75.8, these will automatically start logging.
An example complete data packet would be like (prepended by node ID):

[123] C:33.5 H:80 120W

Edit: forgot to mention each message has to end with a newline.
Title: Re: Test gateway (Pi) without Moteino?
Post by: LukaQ on January 10, 2017, 11:16:11 AM
Hello,

I must be doing something wrong, since even what you posted doesn't create the node and for that reason node count stays at 0.
I did try different string before, for GAL and GPM which is also in metrics.js, but same result.

This is what I have already tried:
I turned of BT since it was using ttyAMA0
I could read and write out to ttyAMA0 (when write out, I was reading outgoing data with serial to usb on pc side)
I could write with python script and with other python script read, what was sent, all was ok.
This is "stock" image out of PiBakery, only setting WIFI and password
Login shell over serial is on, if not, there is no ttyAMA0
The last thing I didn't try now is, using converter on usb of PI3, but did before with OK data, but not seeing anything in gateway
I didn't use boost, with scope baud rate is only about 20 Hz off and don't think its any problem. Baud rate is 19200

In some of the above cases I didn't have TX of PI connected, since I think there is nothing to be sent out, am I right?

For the last try I had serial to usb on PI's usb, serial was send by arduino, I did see correct data with python script, but not with gateway (yes gateway was also changed to right inputs in all cases, this one was ttyUSB0)

What can I do/try?
Title: Re: Test gateway (Pi) without Moteino?
Post by: Felix on January 10, 2017, 11:22:21 AM
Your problem is the Pi gpio serial.

1. disable ttyama0 console.
2. enable the uart.

From this link (http://elinux.org/RPi_Serial_Connection):

QuoteNOTE FOR RASPBERRY PI 3: The Raspberry pi 3 has changed things a bit and you might need to add the option enable_uart=1 at the end of /boot/config.txt (see this post by a Pi Engineer)

Otherwise you could just use a USB serial adapter like the FTDIAdapter (https://lowpowerlab.com/shop/product/90) or similar, then your serial port would be /dev/ttyUSB0 or something like that.

Use minicom to test your serial connection. If minicom can open it and see the data coming in, then the gateway app should also.
Good luck.
Title: Re: Test gateway (Pi) without Moteino?
Post by: LukaQ on January 10, 2017, 12:55:22 PM
Hello,

I had uart=1, serial console=0,

both screen and minicom show data on /dev/ttyUSB0, like so:
[123] C:33.5 H:80 120W[123] C:33.5 H:80 120W[123] C:33.5 H:80 120W....

my adapter is with CP2102

What now?
Title: Re: Test gateway (Pi) without Moteino?
Post by: Felix on January 10, 2017, 01:11:08 PM
I think you're missing newlines after each message.
Also have you configured the GUI to use /dev/ttyUSB0 instead of ttyAMA0 ?
Title: Re: Test gateway (Pi) without Moteino?
Post by: LukaQ on January 10, 2017, 01:37:14 PM
Hello,

I don't have newline, will change that
I do have GUI set to use /dev/ttyUSB0 (arduino is 5v logic as is)

AND it works, newline was missing and that made it not work

Is there live graph, something like moving as data comes in or as time passes?


Felix, you have something special here, I prefer this over OEM, very good job you did and with product you have!

Title: Re: Test gateway (Pi) without Moteino?
Post by: Felix on January 10, 2017, 02:56:21 PM
Great,
I initially missed specifying that newline is required after each message.
Usually the receiving moteino does all that formatting including adding the sender ID and the RSSI and newline to each packet received.
The newline is how the gateway.js app separates between messages.

QuoteIs there live graph, something like moving as data comes in or as time passes?

Yes as long as the tokens received are matching a metric which is set as graph:1 it should start logging automatically, when you click that metric in the node details you will see the graph. If you leave the zoom level at the default latest zoom (ie you do not zoom to a different view which is not including the latest received point), then the graph should slide to the left as new data is coming in.

Thanks for the feedback, glad you find it useful.
Title: Re: Test gateway (Pi) without Moteino?
Post by: ababak on July 29, 2017, 03:19:15 PM
Hi,

I am trying to test the Gateway without the nodes too. It looks like I have similar problems and reading this thread doesn't help.

Here's my setup:
MightyHat with Raspberry Pi 2. The Gateway is running.

I am connecting to serial port like this:
sudo minicom -b 19200 -o -D /dev/ttyAMA0
And I don't get any response here.

When I connect a Serial Monitor via FTDI I can see the feedback there. So when I paste a "KEY?" command to minicom window I can see the reply in the SerialMonitor on my Mac.

When I open a Gateway Log/Terminal I see this:
10:07:13 PM : SERVERTIME OFFSET: 274ms
10:07:13 PM : Connect

When I switch to "Send raw data" window and send "KEY?", the only place where I see the result is again my Serial Monitor.

So I tried sending data from Python like this:
>>> import serial
>>> sp = serial.Serial("/dev/ttyAMA0", 19200, timeout=1.5)
>>> sp.write("[99] F:70.15 H:30 [RSSI:-80]\n")
29

and tried to read back the response but again, no response anywhere except SerialMonitor.

I tried closing Serial Monitor and stopping Gateway but still haven't got any response from serial port on my Pi.

I checked the /boot/config.txt, checked the permissions on /dev/ttyAMA0, checked the gateway log and didn't find anything suspicious.

Could you suggest what am I doing wrong or how to debug this issue?

Thank you.

Regards,
Andrey
Title: Re: Test gateway (Pi) without Moteino?
Post by: Felix on July 31, 2017, 09:11:02 AM
You cannot randomly connect several things to a serial port as if they are the real endpoints sending/receiving data.
Serial is between 2 (two) endpoints. While you might sniff the port with a FTDI or a logic analyzer, that's not meant as a means to replace one of the endpoints.

Also the data you are writing is invalid, the gateway software is expecting this type of format:

sp.write("F:70.15 H:30\n")

You say you send this from python, but you send that back to the Mighty Hat? Are you sure you understand the (two: sending and receiving) parts involved here?
It's the Hat that sends that data to your Pi via serial.
Title: Re: Test gateway (Pi) without Moteino?
Post by: ababak on July 31, 2017, 09:53:46 AM
Yes, it looks that I was doing something wrong here :)
Title: Re: Test gateway (Pi) without Moteino?
Post by: ababak on July 31, 2017, 09:56:17 AM
So what is the easiest way to emulate some events without another Moteino that sends some data over the air?
Title: Re: Test gateway (Pi) without Moteino?
Post by: Felix on July 31, 2017, 10:44:05 AM
Just hook up another serial device over your Pi header.
Or make the Hat send some random made up data.
Sometimes it really pays to look around at sample sketches that I put out in the RFM69 library.
Here's a random data generator (https://github.com/LowPowerLab/RFM69/blob/master/Examples/RandomNumbers/RandomNumbers.ino) that will make nice graphs in the Gateway UI.

Title: Re: Test gateway (Pi) without Moteino?
Post by: ababak on February 02, 2018, 05:59:46 AM
After a long break, I was able to get back to MightyHat. This time I've prepared a Moteino that sends a random temperature. MightyHat successfully receives the packets and shows this random temperature on the LCD. But there is nothing showing up on the gateway.
Sending data from gateway to Moteino node works just fine, Moteino shows the received text in its console.
I've double-checked the /boot/config.txt serial settings.
Then I tried to stop the gateway service and connect to /dev/ttyAMA0:
sudo minicom -b 19200 -o -D /dev/ttyAMA0

And I can't get any feedback from there while it should send the same string it shows on the LCD.
Can you help me to diagnose whether this is a software or a hardware problem?

Thank you.
Cheers,
Andrey
Title: Re: Test gateway (Pi) without Moteino?
Post by: Felix on February 02, 2018, 09:31:33 AM
Hey Andrey!
Is your Gateway software a stable working install?
Remember to match the BAUD on the MightYHat to that in the Gateway settings page.

After that check, look in the gateway.sys.log file to see incoming serial data.
After that check, make sure your metrics match one of the definitions in metrics.js. The random sending temperature example in the RFM69 library (https://github.com/LowPowerLab/RFM69/blob/master/Examples/RandomNumbers/RandomNumbers.ino) will work without needing any changes in metrics.
Title: Re: Test gateway (Pi) without Moteino?
Post by: ababak on February 03, 2018, 07:41:25 AM
Hey Felix!

I am using the fresh software without any modifications except setting FREQUENCY to RF69_433MHZ. The baud rate is set to 19200 everywhere. I am using the default RandomNumbers sketch so the format is recognizable by the gateway and the temperature is shown on the LCD.

Here's what's inside the log:
[02-02-18_07:37:06.892] [INFO]  LOADING USER METRICS MODULE [_example.js]
[02-03-18_11:40:13.020] [INFO]  LOADING USER METRICS...
[02-03-18_11:40:13.052] [INFO]  LOADING USER METRICS MODULE [_example.js]
[02-03-18_13:44:08.737] [INFO]  LOADING USER METRICS...
[02-03-18_13:44:08.770] [INFO]  LOADING USER METRICS MODULE [_example.js]
[02-03-18_14:05:37.370] [INFO]  LOADING USER METRICS...
[02-03-18_14:05:37.402] [INFO]  LOADING USER METRICS MODULE [_example.js]
[02-03-18_14:12:12.153] [INFO]  AUTHORIZING CONNECTION FROM ::1:36798
[02-03-18_14:12:12.176] [INFO]  NEW CONNECTION FROM 192.168.10.3
[02-03-18_14:12:39.780] [LOG]   NODEACTION: {"nodeId":"98","action":"Sending some text"}
[02-03-18_14:19:46.375] [INFO]  AUTHORIZING CONNECTION FROM ::1:36810
[02-03-18_14:19:46.393] [INFO]  NEW CONNECTION FROM 192.168.10.3

The NODEACTION line shows that I've sent a command through gateway terminal. That's what I've got from the node:
ok!
ok!
ok!
ok!
ok!
ok!
[1] SENDING SOME TEXT   [RX_RSSI:-61] - ACK sent
ok!
ok!


As far as I understand there should be the incoming serial data which is missing. Anything else I can check to pinpoint teh problem?

Thank you.

Regards,
Andrey
Title: Re: Test gateway (Pi) without Moteino?
Post by: Felix on February 03, 2018, 06:54:18 PM
Looks like serial connection is OK
The Multiple loads of _example.js looks suspicious, not sure what to make of that. Is this log contiguous?

I don't see any of your data coming from your Random generator node?

Your gateway node ID is [1] right?
The log is confusing because it shows your node [1] sent this text: "SENDING SOME TEXT"
When in fact your reported that you sent it from the terminal?

The sketch assumes your Gateway is node ID 1, and the rest of your network is up to [255]. Make sure you are sending to node 1 in your Random generator sketch.
Title: Re: Test gateway (Pi) without Moteino?
Post by: ababak on February 04, 2018, 08:25:54 AM
The multiple loads of _example.js are due to rebooting the Pi, the log is contiguous.

Yes, I don't see any of the data coming from the node as well.

Yes, I am using default code, the gateway is 1, the node is 98. The random generator is also using a default code so it's sending data to GATEWAYID which is 1. The MightyHat successfully gets the data as it shows it on the LCD.

I was using a built-in gateway terminal to send the "Sending some text" text to node 98, see attachment. So it looks like Pi is able to send data to MightyHat but cannot receive anything back.

Is there anything else I should check?

Thank you.
Title: Re: Test gateway (Pi) without Moteino?
Post by: LukaQ on February 04, 2018, 09:44:30 AM
hey,

You should check that you do get data on serial port. First you need to see data there. Only then you you need to look at gateway.sys.log, gateway.db and gateway_nonmatches.db.

First show us that you do in fact get serial
Title: Re: Test gateway (Pi) without Moteino?
Post by: ababak on February 04, 2018, 12:07:48 PM
Hey Luka,

That's exactly my problem, I can't get anything from the serial port of my Pi. Although it works for sending data from the gateway terminal.
If I connect an FTDI Adapter to MightyHat I see all the expected data. But nothing shows up on the Pi side - neither from the gateway logs nor from the minicom session directly.
Title: Re: Test gateway (Pi) without Moteino?
Post by: LukaQ on February 04, 2018, 01:29:22 PM
Ok, then use some serial port terminal, like realterm or Arduino IDE, you must see something. If you don't see anything in any serial program, then we'll have to assume, that Moteino is not getting anything as one option
Title: Re: Test gateway (Pi) without Moteino?
Post by: Felix on February 05, 2018, 04:52:03 PM
Ok, first stop the gateway app (sudo systemctl stop gateway) and use minicom or any serial app in the terminal, to monitor your MightyHat GPIO serial (/dev/ttyAMA0).
Once that works, we can debug further.
Title: Re: Test gateway (Pi) without Moteino?
Post by: ababak on February 06, 2018, 02:17:52 PM
Unfortunately, no information is coming from /dev/ttyAMA0:

sudo minicom -b 19200 -o -D /dev/ttyAMA0


Although when I copy/paste "98:Test string" to minicom I see a response in the terminal connected to node 98. So it works for sending data but does not work for receiving data from the MightyHat. The MightyHat itself receives the radio data from node 98 and I see that on its LCD and if I connect an FTDI directly to MightyHat and listen to the Serial traffic.

If there's nothing else to be checked at a software level, I'll try to use another Pi.

Thanks.
Title: Re: Test gateway (Pi) without Moteino?
Post by: Felix on February 06, 2018, 02:26:01 PM
Looks like a hardware/connection issue, trace your TX/RX signals from the MHat to the GPIO header and see if the connection is solid all the way, you can do it with continuity on your DMM. If you have a scope or logic analyzer you could actually decode the messages.
Make sure not to have an FTDI-Adapter connected to the MHat while connected to the Pi, it is only for programming the MHat, only the 2 devices should be on a serial bus.
Title: Re: Test gateway (Pi) without Moteino?
Post by: ababak on February 11, 2018, 06:30:00 AM
Quote from: Felix on February 06, 2018, 02:26:01 PM
Looks like a hardware/connection issue, trace your TX/RX signals from the MHat to the GPIO header
Hi Felix,
Am I right that there should be a connection between these two points? (There is no in my case)

I mean in my case there is no electrical connection between these points. I thought the multimeter should show one.
Title: Re: Test gateway (Pi) without Moteino?
Post by: Felix on February 11, 2018, 01:33:55 PM
Oops, yes you are correct, there should definitely be a connection. The MightyHat has a trace going from the Atmega328p TX pin to the GPIO RX pin.
So ... depending where the break is, you might just fix it with a wire if that's the easiest fix.
Title: Re: Test gateway (Pi) without Moteino?
Post by: ababak on February 18, 2018, 01:24:24 PM
Cool, after soldering a wire it works now!
Thanks.