Browse Source

- Eine funktionierende Version von der T-Call Steuerung
- ein PoC für die Ablage von ConfigOptionen in einer extra Config-Datei (main.py)

Chris Hoelzel 4 years ago
parent
commit
dc29e59ffa
5 changed files with 231 additions and 4 deletions
  1. 110 0
      example/T-Call_SIM800L.py
  2. 16 0
      main.py
  3. 98 0
      t-call.py
  4. 3 0
      test/config.json
  5. 4 4
      test/esp_uart.py

+ 110 - 0
example/T-Call_SIM800L.py

@@ -0,0 +1,110 @@
+'''
+  Using your phone:
+    - Disable PIN code on the SIM card
+    - Check your balance
+    - Check that APN, User, Pass are correct and you have internet
+  Ensure the SIM card is correctly inserted into the board
+  Ensure that GSM antenna is firmly attached
+
+  NOTE: While GSM is connected to the Internet, WiFi can be used only in AP mode
+
+  More docs on GSM module here:
+  https://github.com/loboris/MicroPython_ESP32_psRAM_LoBo/wiki/gsm
+
+  Author: Volodymyr Shymanskyy
+'''
+import socket
+import machine
+import time
+import sys
+import gsm
+
+SIM800L_IP5306_VERSION_20190610 = 0
+SIM800L_AXP192_VERSION_20200327 = 1
+SIM800C_AXP192_VERSION_20200609 = 2
+SIM800L_IP5306_VERSION_20200811 = 3
+
+
+# Please change to the version you use here, the default version is IP5306
+board_type = SIM800C_AXP192_VERSION_20200609
+
+
+# APN credentials (replace with yours)
+GSM_APN = ''  # Your APN
+GSM_USER = ''  # Your User
+GSM_PASS = ''  # Your Pass
+
+UART_BAUD = 115200
+
+# defaule use SIM800L_IP5306_VERSION_20190610
+MODEM_POWER_PIN = 23
+MODEM_RST = 5
+MODEM_PWRKEY_PIN = 4
+MODEM_TX = 27
+MODEM_RX = 26
+LED_PIN = 13
+
+
+if board_type == SIM800C_AXP192_VERSION_20200609:
+    LED_PIN = 12
+    MODEM_POWER_PIN = 25
+    MODEM_RST = 0
+
+    # Power on the GSM module
+GSM_POWER = machine.Pin(MODEM_POWER_PIN, machine.Pin.OUT)
+GSM_POWER.value(1)
+
+LED = machine.Pin(LED_PIN, machine.Pin.OUT)
+LED.value(1)
+
+if MODEM_RST > 0:
+    MODEM_RST = machine.Pin(MODEM_RST, machine.Pin.OUT)
+    MODEM_RST.value(1)
+
+GSM_PWR = machine.Pin(MODEM_PWRKEY_PIN, machine.Pin.OUT)
+GSM_PWR.value(1)
+time.sleep_ms(200)
+GSM_PWR.value(0)
+time.sleep_ms(1000)
+GSM_PWR.value(1)
+
+# Init PPPoS
+
+gsm.debug(True)  # Uncomment this to see more logs, investigate issues, etc.
+
+gsm.start(tx=MODEM_TX, rx=MODEM_RX, apn=GSM_APN,
+          user=GSM_USER, password=GSM_PASS)
+
+sys.stdout.write('Waiting for AT command response...')
+for retry in range(20):
+    if gsm.atcmd('AT'):
+        break
+    else:
+        sys.stdout.write('.')
+        time.sleep_ms(5000)
+else:
+    raise Exception("Modem not responding!")
+print()
+
+print("Connecting to GSM...")
+gsm.connect()
+
+while gsm.status()[0] != 1:
+    pass
+
+print('IP:', gsm.ifconfig()[0])
+
+# GSM connection is complete.
+# You can now use modules like urequests, uPing, etc.
+# Let's try socket API:
+print("Connected !")
+addr = socket.getaddrinfo('micropython.org', 80)[0][-1]
+s = socket.socket()
+s.connect(addr)
+s.send(b'GET / HTTP/1.1\r\nHost: micropython.org\r\n\r\n')
+data = s.recv(1000)
+print(data)
+s.close()
+
+# You should see terminal version of StarWars episode
+# Just like this: https://asciinema.org/a/1457

+ 16 - 0
main.py

@@ -7,6 +7,22 @@ from machine import Timer
 
 from SIM import *
 
+# todo: Hier muss nun ein configparser rein
+    #   >> import ujson
+        # >>> with open('test/config.json','r') as f:
+        # ...     try:
+        # ...         ob = ujson.load
+        # load            loads
+        # ...         ob = ujson.load(f)
+        # ...     except:
+        # ...         print("error")
+        # ...
+        # ...
+        # ...
+        # >>>
+        # >>> print(ob["var1"])
+
+
 znr = "017643609376"
 atxt = "Alarm in Garage 1 ausgeloest"
 wz = 600

+ 98 - 0
t-call.py

@@ -0,0 +1,98 @@
+# Python TTGO T-Call Klasse
+
+# 2022-03-16 - cho - erste Version erstellt
+import machine
+
+class tcall:
+
+    MDM_PWR = None
+    MDM_PWR_PIN = None
+    MDM_RST_PIN = None
+    MLED = None
+    MLED_PIN = None
+
+
+    def __init__(MDM_PWR_PIN,MDM_RST_PIN,MLED_PIN):
+        self.setmdmpwrpin(MDM_PWR_PIN)
+        self.setmdmrstpin(MDM_RST_PIN)
+        self.setmledpin(MLED_PIN)
+
+    # setter and getter methods
+    def setmdmpwrpin(pin):
+        self.MDM_PWR_PIN = pin
+        self.MDM_PWR = machine.Pin(pin, machine.Pin.OUT)
+
+    def getmdmpwrpin(pin):
+        return self.MDM_PWR_PIN
+
+    def getmdmpwr():
+        return self.MDM_PWR
+
+    def setmdmrstpin(pin):
+        self.MDM_RST_PIN = pin
+
+    def getmdmrstpin():
+        return MDM_RST_PIN
+
+    def setmledpin(pin):
+        self.MLED_PIN = pin
+        self.MLED = machine.Pin(pin, machine.Pin.OUT)
+
+    def getmledpin(pin):
+        return self.MLED_PIN
+
+    def getmled():
+        return self.MLED
+
+    # Statusreadout - Methoden liefern Rueckgabewerte
+    def getmdmpwrstate():
+        if self.MDM_PWR is not None:
+            return self.MDM_PWR.value()
+        else:
+            return 0
+
+    def getmdmmledstate():
+        if self.MLED is not None:
+            return self.MLED.value()
+        else:
+            return 0
+
+    # Modem PowerSwitch mit Uebergabe des States
+    # todo: Klasse testen
+    # Folgende Stati können übergeben werden
+    #   0 = aus
+    #   1 = an
+    #   [3 = Switch on->off / off->on] default
+    def mdmpwrsw(state=3):
+        if self.MDM_PWR is not None:
+            # angegebenen status schalten
+            if  state >= 0 and state <= 1:
+                self.MDM_PWR.value(state)
+
+            # An/Aus Schalter, einfach das Gegenteil von dem was aktuell ist
+            if state = 3:
+                if self.getmdmpwrstate() = 0:
+                    self.MDM_PWR.value(1)
+                else:
+                    self.MDM_PWR.value(0)
+
+    # Modem Reset
+    # todo: Test dieser Funktion auf dem Board
+    def mdmrstsw():
+        import time
+        self.MDM_PWR.value(1)
+        time.sleep_ms(500)
+        self.MDM_PWR.value(0)
+
+
+    # Machine LED PowerSwitch
+    # todo: Kopie der Funktionsweise von mdmpwrsw
+    def mledpwrsw(state):
+        if  state >= 0 and state <= 1:
+            self.MLED.value(state)
+
+
+    # Machine LED blink
+    # todo: Implemetierung ausstehend
+    def mledblink(speed):
+        pass

+ 3 - 0
test/config.json

@@ -0,0 +1,3 @@
+{
+    "var1":"value"
+}

+ 4 - 4
test/esp_uart.py

@@ -9,8 +9,8 @@ import os
 print("warte 5s auf Abbruch ...")
 time.sleep(5)
 
-uartOUT = UART(1, baudrate=115200)
-uartIN = UART(0,baudrate=115200)
+uartOUT = UART(26, baudrate=115200)
+uartIN = UART(27,baudrate=115200)
 
 while True:
 
@@ -20,8 +20,8 @@ while True:
     print("AT Kommando senden")
     uart.write('ATI\r\n')
 
-    print("Repl anhängen")
-    os.dupterm(UART(0, 115200))
+    #print("Repl anhängen")
+    #os.dupterm(UART(0, 115200))
 
     #uart.write('AT+CPIN?\r\n')
     #uart.write('AT+CPIN=2389\r\n') # PIN Check