Send python data to Node js virtual pin

Hello all,
I’m stuck again.
I’m running a python script (similar to code below) on Raspberry pi 3 to monitor power/current.
I’m using INA3221 similar to INA219 current monitor. I’m trying to figure out how to send data (like voltage) to Node js blynk client so I can attach it to virtual pin and display it in widget on blynk app.
Please share if there’s an easy method of doing this.
Thank you in advance.

#!/usr/bin/env python
#
# Test SDL_Pi_INA3221
# John C. Shovic, SwitchDoc Labs
# 03/05/2015
#
#

# imports

import sys
import time
import datetime
import random 
import SDL_Pi_INA3221

# Main Program

print ""
print "Test SDL_Pi_INA3221 Version 1.0 - SwitchDoc Labs"
print ""
print "Sample uses 0x40 and SunAirPlus board INA3221"
print " Will work with the INA3221 SwitchDoc Labs Breakout Board"
print "Program Started at:"+ time.strftime("%Y-%m-%d %H:%M:%S")
print ""

filename = time.strftime("%Y-%m-%d%H:%M:%SRTCTest") + ".txt"
starttime = datetime.datetime.utcnow()

ina3221 = SDL_Pi_INA3221.SDL_Pi_INA3221(addr=0x40)

# the three channels of the INA3221 named for SunAirPlus Solar Power Controller channels (www.switchdoc.com)
LIPO_BATTERY_CHANNEL = 1
SOLAR_CELL_CHANNEL   = 2
OUTPUT_CHANNEL       = 3


while True:

  	print "------------------------------"
  	shuntvoltage1 = 0
  	busvoltage1   = 0
  	current_mA1   = 0
  	loadvoltage1  = 0


  	busvoltage1 = ina3221.getBusVoltage_V(LIPO_BATTERY_CHANNEL)
  	shuntvoltage1 = ina3221.getShuntVoltage_mV(LIPO_BATTERY_CHANNEL)
  	# minus is to get the "sense" right.   - means the battery is charging, + that it is discharging
  	current_mA1 = ina3221.getCurrent_mA(LIPO_BATTERY_CHANNEL)  

  	loadvoltage1 = busvoltage1 + (shuntvoltage1 / 1000)
  
  	print "LIPO_Battery Bus Voltage: %3.2f V " % busvoltage1
  	print "LIPO_Battery Shunt Voltage: %3.2f mV " % shuntvoltage1
  	print "LIPO_Battery Load Voltage:  %3.2f V" % loadvoltage1
  	print "LIPO_Battery Current 1:  %3.2f mA" % current_mA1
  	print

  	shuntvoltage2 = 0
  	busvoltage2 = 0
  	current_mA2 = 0
  	loadvoltage2 = 0

  	busvoltage2 = ina3221.getBusVoltage_V(SOLAR_CELL_CHANNEL)
  	shuntvoltage2 = ina3221.getShuntVoltage_mV(SOLAR_CELL_CHANNEL)
  	current_mA2 = -ina3221.getCurrent_mA(SOLAR_CELL_CHANNEL)
  	loadvoltage2 = busvoltage2 + (shuntvoltage2 / 1000)
  
  	print "Solar Cell Bus Voltage 2:  %3.2f V " % busvoltage2
  	print "Solar Cell Shunt Voltage 2: %3.2f mV " % shuntvoltage2
  	print "Solar Cell Load Voltage 2:  %3.2f V" % loadvoltage2
  	print "Solar Cell Current 2:  %3.2f mA" % current_mA2
  	print 

  	shuntvoltage3 = 0
  	busvoltage3 = 0
  	current_mA3 = 0
  	loadvoltage3 = 0

  	busvoltage3 = ina3221.getBusVoltage_V(OUTPUT_CHANNEL)
  	shuntvoltage3 = ina3221.getShuntVoltage_mV(OUTPUT_CHANNEL)
  	current_mA3 = ina3221.getCurrent_mA(OUTPUT_CHANNEL)
  	loadvoltage3 = busvoltage3 + (shuntvoltage3 / 1000)
  
  	print "Output Bus Voltage 3:  %3.2f V " % busvoltage3
  	print "Output Shunt Voltage 3: %3.2f mV " % shuntvoltage3
  	print "Output Load Voltage 3:  %3.2f V" % loadvoltage3
  	print "Output Current 3:  %3.2f mA" % current_mA3
  	print
		

	#
	time.sleep(2.0)

I don’t know about “easy” since Blynk Python is in Alpha stage… but why not just incorporate Blynk into what you already have running?

Or install Node-Red on the Pi and use the GPIO and Blynk-ws nodes to read, process and output the data to Blynk?

Pete.

For weeks I’ve been trying to port alI of my python code to node js but the current sensor module (ina3221) has barely any documentation (that I can understand) and I could not find any examples pertaining to node js. I also tried running Blynk with the python library but I was not able to figure out how to connect to my local server instead of the blynk cloud. If it’s possible, maybe someone can show how to connect to my local server via python Blynk library.

Does anybody know if it’s possible to connect to local server with python Blynk library?

I have no idea on the sketch level syntax… but you could try editing the library… BlynkLib.py both for the server and the port, as at least the normal one would need to change to 8080 from 8442 for local server.

image

Looking at it a bit closer, I wonder if something like this will work… :thinking:

blynk = BlynkLib.Blynk(BLYNK_AUTH, 'xxx.xxx.xxx.xxx', 8080)

1 Like

blynk = BlynkLib.Blynk(BLYNK_AUTH, 'xxx.xxx.xxx.xxx', 8080)

Thank you Gunner, that worked great.:smile:
it’s funny I had tried many variations of that similar line of code and no luck.
There is one downside to the Python Blynk library tough, it maxes CPU load on 1 core, unlike Node js Blynk library where CPU load is only a fraction of that.

Well, it is still in Alpha stage… probably more a pet project of one of the developers then anything official.