maks / ginlong-lua

Lua script to poll data from Ginlong solar invertors
BSD 2-Clause "Simplified" License
0 stars 0 forks source link

Crontab #1

Open Gronhund opened 10 years ago

Gronhund commented 10 years ago

Hi. After your response on: http://forums.whirlpool.net.au/forum-replies.cfm?t=1951601&p=2 I have tried out your projekt on my Raspberry, but the Crontab gives me an error: "bad command errors in crontab file, can't install" I don't know crontabs very well, so I can't see what the problem is. I have tried a few variations for only the first line, but nothing seems to work (I have altered the directory so it looks in the right place). Is there something else that needs to be set up, or could there be another problem? Best regards Mikkel

Gronhund commented 10 years ago

By the way, in your setup description, you spelled Ginlong with an extra g (ginglong): git clone https://github.com/maks/ginglong-lua.git I couldn't figure out why it wouldn't install ;-) Best regards Mikkel

maks commented 10 years ago

sorry for the slow reply Mikkel. How did you go about adding the crontab entry, did you use crontab -e and then copy/paste in each line? I'm pretty sure the entries I have are from the actual crontab I used on my RPi but I'll double check this evening. Also please check to make sure you have the last commit I pushed up on sunday afternoon, as that has a fix for the shell script connect thats called from crontab that prior to the fix, didn't setup the Bluetooth connection to the invertor.

Gronhund commented 10 years ago

Thank you for your reply. No need to apologise. You answered very quickly (thank you).

Yes, I have downloaded the latest version. I use CronTab - e and copy all lines at once. But I have also tried deleting the two lines, so I only end up with one line. Still with no luck. I tried to copy the CronTab line from the Pearl code that you also referred to, and it doesn't complain about that. Best regards Mikkel

maks commented 10 years ago

So this is exactly what I have in my crontab right now:

# m h  dom mon dow   command
*/1 7-21 * * * cd /home/maks/ginlong-lua; ./poll-invertor.lua >> /tmp/invertor.log 2>&1
*/10   7 * * * cd /home/maks/ginlong-lua; ./connect
0   22   * * * rfcomm release 0 >> /tmp/rfcomm.log 2>&1

note this is for the root user, though it should work for a normal user as long as the permissions on the bluetooth device are set, I just havent had time to do that yet.

Also I'd recommend just trying to run the connect shell script by hand first to make sure it works ok for you. You can check that you are connected using:

rfcomm show 0

Also you'll need to make sure you have the rfcomm config set up, heres my /etc/bluetooth/rfcomm.conf

rfcomm0 {
        bind no;        
        device 00:12:34:56:78:AB;
        channel 1;
        comment "ginlong invertor";
}

of course I've just put in a fake device address - you can find the address of your inverter by doing:

hcitool scan

Hope that helps, I've also updated the readme with this info and thanks for spotting the typo in the git clone line I've fixed that up too.

Gronhund commented 10 years ago

Hi again. Thank you for your answers. I am a newbi so I appriciate your help very much. The crontab is now filled out and saved. Looks like I had to manually type the lines in (and not copy them). I typed them in one at a time, and saved it before typing in the next. That seemed to do the trick. The rfcomm.conf seems to be typed in correctly. The hcitool scan found the adress, and I typed that in. However when I type in "rfcomm connect 0" in the terminal (doesn't matter if I'm root or not and doesn't matter if I'm in the Ginlong-Lua directory or not) it says "Can't connect RFCOMM socket: Connection refused". I have to write "rfcomm home/pi/ginlong-lua connect 0" for it to work. But still I can't get the Show to work. That says "Get info failed: No such device". The invertor.log says the following: "Ginlong Inverter Poller started

using Pvoutput.org API key: XXXXXXXX /usr/bin/lua: ./poll-invertor.lua:169: /dev/rfcomm0: Permission denied stack traceback: [C]: in function 'assert' .poll-invertor.lua:169: in main chunk [C]: in ?"

I have given the etc/Bluetooth/rfcomm0 read&write permissions for all users. but this is the dev/rfcomm0 (which does not exist). If the connect script had worked, would this mean that the etc/Bluetooth/rfcomm0 would have been transfered to the dev/ directory? By the way, The [C] is still in the code. I don't know were that comes from? Best regards Mikkel

maks commented 10 years ago

@Gronhund very sorry about this, I forgot to include the step to provide the "pincode" for your invertor to bluez! When you run on a desktop linux system, you'd normally get a GUI dialog popup asking you for the pincode of the device you are connecting to but when you use the RPI "headless" you need to set this manually instead and I unfortunately thats not even properly documented in the bluez docs. So what you need to do is edit a file in /var/lib/bluetooth/XX:XX:XX:XX/pincodes and add in there the pincode for your invertor which is probably still set on the default of 0000, so in that file youd just have one line like:

00:12:34:56:78:AB 0000

Now note that in the file path above, the XX:XX:XX:XX is your Bluetooth adapter in your RPI ID and NOT your invertor, the invertor ID goes inside the file along with the pincode.

You can find the address of your bluetooth adapter with:

hcitool dev
Gronhund commented 10 years ago

I haven't really had time to try to look further into this at the moment. So all I have done is to add the "pincodes" file with the information you provide (it wasn't there so I created it). But the result is the same. Same error message as previously in the "invertor.log". But if I look in the "dev" directory, there is no "rfcomm0" file. Is this because it didn't get connected?

Gronhund commented 10 years ago

You talk about "bluez". I haven't installed that. I installed the default Raspbian image from the Raspberry Pi homepage, and then I have installed the things that you mentioned. Do I need to install "Bluez" aswell or is it preinstalled in the Raspbian image? Again thank you for your responses. I really do appreciate them. Best regards Mikkel

maks commented 10 years ago

Mikkel yes you need to have the bluez packages installed as they are the bluetooth libraries in linux. It would depend what the default packages are in that img, sorry I dont use it myself.

I wanted something small, so I installed the image from img from http://minibianpi.wordpress.com/

I then installed the following:

apt-get install vim git htop ntpdate
apt-get install lua5.2 bluez curl ## for ginglong poller
dpkg-reconfigure tzdata ## then reboot to have cron pickup the TZ change

If you don't see /dev/rfcomm0 then your serial connection to the invertor over bluetooth is not setup correctly so you need to get that working first.

I'd start with running:

hctool scan

to see if your invertor shows up. If it does then try:

rfcomm connect 0

and after that:

rfcomm show 0

if you see output then like:

rfcomm0: 00:01:AB:CC:AC:CC -> 00:A1:B2:00:AC:DC channel 1 connected [reuse-dlc release-on-hup tty-attached]

then you are good to go to try running my lua script (try running it by hand first before using crontab)

Gronhund commented 10 years ago

Hi again. Just for the fun of it, I tried out the Minibian, but didn't get very far, because I use a WIFI dongle :-( So I went back to the Rasbian again ;-) But some how the connection script works now (I can't see that I did something different). So now it connects and executes poll-invertor.lua. The CronTab has to be made by Root user, isn't this correct? So now that the Poll-Invertor.lua script is running, I was hoping to se some data when I log into my PVOutput account. But there is none. The Invertor.log file is also pretty empty. Is says: "Ginlong Invertor Poller started

using Pvputput.org API key:XXXXXX try 0" And thats it. It doesn't look like I get into ParseResponse or SendToPVOutput in the Poll-Inverter.lua. Any suggestions? Best regards Mikkel

Gronhund commented 10 years ago

Hold your horses. Now I get a "Data bad" but that is ok. I will get back to you tomorrow with additional information. Best regards Mikkel

maks commented 10 years ago

Mikkel yes try running the lua script a couple of times again, I have seen that from time to time, the invertor just sends rubbish data in response. Let me know if your are still having problems and thanks again for being so patient with trying to get my script working, you've really helped me see where to improve the documentation.

Gronhund commented 10 years ago

Ok. I had it up and running yesteday evening, but this morning it did not work. But it looks like I have a bad connection in my USB hub, so until I get that fixed, lets assume that the whole thing works. It does however seem like I have a problem setting the connection to the bluetooth inverter (connect file), so I do that manually as root, but let's see if it isn't the faulty USB hub that makes the problem. However I have another question. As I told you, I have a 3kW (bluetooth+RS485) and a 2kW (only RS485). I have bought a RS485-to-USB converter. You told me earlier that this should work aswell. I haven't testet it yet, but do you think it should work out of the box or do I have to install anything to get it to work. If you don't know (or have a idea) I willl just search the internet when I have the time, but you do know a lot (compared to me), so I might aswell ask you ;-) A bonus question is, that If I had two GinLong 3kW inverteres, would I just have to add the MAC and pincode in the "pincodes" file, and then it should log from both? Best regards Mikkel