File: region_get_set.py

package info (click to toggle)
gtk-meshtastic-client 1.5-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 3,056 kB
  • sloc: python: 4,794; xml: 64; makefile: 3
file content (118 lines) | stat: -rw-r--r-- 1,979 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
"""Simple program to demo how to use meshtastic library.
   To run: python examples/info.py
"""

import meshtastic
import meshtastic.serial_interface

from enum import Enum

class RegionCode(Enum):
    UNSET = 0
    """
    Region is not set
    """
    US = 1
    """
    United States
    """
    EU_433 = 2
    """
    European Union 433mhz
    """
    EU_868 = 3
    """
    European Union 868mhz
    """
    CN = 4
    """
    China
    """
    JP = 5
    """
    Japan
    """
    ANZ = 6
    """
    Australia / New Zealand
    """
    KR = 7
    """
    Korea
    """
    TW = 8
    """
    Taiwan
    """
    RU = 9
    """
    Russia
    """
    IN = 10
    """
    India
    """
    NZ_865 = 11
    """
    New Zealand 865mhz
    """
    TH = 12
    """
    Thailand
    """
    LORA_24 = 13
    """
    WLAN Band
    """
    UA_433 = 14
    """
    Ukraine 433mhz
    """
    UA_868 = 15
    """
    Ukraine 868mhz
    """
    MY_433 = 16
    """
    Malaysia 433mhz
    """
    MY_919 = 17
    """
    Malaysia 919mhz
    """
    SG_923 = 18
    """
    Singapore 923mhz
    """

    def is_region_code(value):
        try:
            RegionCode[value]
        except:
            return False
        return True

interface = meshtastic.serial_interface.SerialInterface()
node = interface.getNode('^local')

#print(node.localConfig.lora)
# Region UNSET is 0

region_int = node.localConfig.lora.region

print(node.localConfig)
print(node.localConfig.lora)

print("The enum member associated with value " + str(region_int) + " is : ", RegionCode(region_int).name)
print("The enum member associated with name US is : ", RegionCode['US'].value)

if region_int == 0:
    new_region = "US"
    if RegionCode.is_region_code(new_region):
        node.localConfig.lora.region = RegionCode[new_region].value
        node.writeConfig("lora")
        print("Changing region to: " + new_region)
    else:
        print(new_region + " is not a valid region")

interface.close()