#Code samples: Gosund SP112

Code tips and tricks for beginners
Post Reply
User avatar
Oli
Posts: 88
Joined: Tue Feb 09, 2021 10:07 am
Location: Germany, Meissen
Has thanked: 19 times
Been thanked: 58 times
Contact:

#Code samples: Gosund SP112

Post by Oli »

This is a functioning demo, it is made very easy for better understanding. Certainly there is still web interface and MQTT or UDP or ESP-now. I later need help with the data logger, which is not so easy. But you can see the pins and watt hours nicely.

I hope it helps someone, have fun ...

Code: [Local Link Removed for Guests]

' HLW8012 / BL0937 / CSE7759
'00=led   02=led2   (05=BL0937-CF)   (04=cf1 hlwbl 12=sel)  13=relais2   14=relais1  adc=button

pin.mode 05, input     'Power Takt  .800W ca 550 Hz
pin.mode 04, input     'Volt A Takt   ,240V=ca 1880Hz 3A=ca 250Hz
PIN.MODE 12, OUTPUT    'select  0=Ampere  1=Volt für pin 04

pin.mode adc, input    'Taste gedückt=0-20 losgelassen=1000-1024
PIN.MODE 14, OUTPUT    'Relais 0=ein
PIN.MODE 13, OUTPUT    'USB 0=ein
PIN.MODE 02, OUTPUT    'blau LED 0=ein
PIN.MODE 00, OUTPUT    'rot LED 0=ein

COUNTER.SETUP 1, 05, 1 'counter1, Pin 05 , rising
timer0 1000, Sekunde


Watt = 0
kwSekunde=0
wSekunde =0
kwh=0.00001
WattS=0.000000001

a=0

Anf:

PIN(02) = 1
PIN(00) = 1
'PIN(14) = 1
PIN(13) = 1
PIN(12) = 1
 



Watt = COUNTER.FREQ(1)
Watt = Watt * 1.437             'Eichung
temp1$ = str$(Watt,"%2.0f")     'Runden                  
Watt = val(temp1$)              'Runden  
temp1$ = str$(kwh,"%4.3f")      'Runden                  
kwStunden = val(temp1$)         'Runden  



'if adc < 30 then t = 1 else t = 0  'Taste gedrückt t = 1 
if adc < 30 then a = 1 - a
PIN(14) = a

wlog Watt , kwStunden , a



pause 600
goto Anf


Sekunde:
wSekunde = Watt * 0.00027777778 'Watt/Sekunde zu w/h
kwSekunde = wSekunde / 1000 'w/h zu kw/h
kwh = kwh + kwSekunde       'jede Sekunde die Partion kW/Sekunde dazuzählen


return

end
You do not have the required permissions to view the files attached to this post.
Post Reply