quentincg / gsm-tc35-python-library Goto Github PK
View Code? Open in Web Editor NEW[Done] Send/receive SMS/MMS/Call and a lot more with GSM TC35 or MC35 module (Python and shell library, multi-platform)
License: MIT License
[Done] Send/receive SMS/MMS/Call and a lot more with GSM TC35 or MC35 module (Python and shell library, multi-platform)
License: MIT License
@janisblaus sent me this issue:
Hi Quentin,
When I try to read the sms that contains utf8 - it comes in some sort of encoding format.
After investigation, I can't reproduce it with my TC35 module...
I'll have to better understand what is happening.
Web interface to:
Issue received from mail:
The message has "@" char at the beginning, it transforms it to "¡" when sending the message out.
It looks like the issue only appears on messages which are non-utf-8, regardless if they are multipart or not.Example of sendSMS that works/fail:
"@Vtests 13 kols 33" - received "¡Vtests 13 kols 33" (fail)
"a@Vtests 13 kols 33" - received "a¡Vtests 13 kols 33" (fail)
"\@Vtests 13 kols 33" - received "\@Vtests 13 kols 33" (works with "\")
"tests 13 kols ā 33 @d" (works)When trying to read a message which contains "@" from the device, it (@ char) is returned as hex "\x00" somwhat similar behavior to this.
It is currently possible to send SMS but not multipart SMS (more than 140 char or more than 70 special char).
The module can handle that but this should be implemented in the library.
What should be done before adding this lib to pypi:
setup.py
(1 hour)Calling multiple times function to get SMS or Phonebook entries will not work every time.
--> Need to investigate, add more logs and fix the issue.
Potential errors:
getLastCallDuration() returns a string ("xxx:xx:xx") which is not optimal to easily get the exact duration in sec/min/hours...
Returning the call duration in sec will solve the "issue".
It would be great to unit-test this library.
Basic example checking what is written to the serial port and sending only specific data into the serial port.
It is not using unittest.mock
(would be better with mock)...
import unittest
from GSMTC35 import GSMTC35
import logging
#from unittest.mock import patch
logger = logging.getLogger()
#logger.setLevel(logging.DEBUG)
# Basic simulation of GSM "hardware" (serial port)
class FakeSerial:
__in_waiting = 0
__read = ""
__write = 0
__check_write = ""
__is_open = True
__is_closed = True
def __init__(self, in_waiting=50, read="OK\r\n", write=50, check_write="", is_open=True, is_closed=True):
self.__in_waiting = in_waiting
self.__read = read.encode()
self.__write = write
self.__check_write = check_write.encode()
self.__is_open = is_open
self.__is_closed = is_closed
def inWaiting(self):
return self.__in_waiting
def read(self, dummy):
return self.__read
def write(self, data):
if len(self.__check_write) > 0:
assert self.__check_write == data
return self.__write
def isOpen(self):
return self.__is_open
def close(self):
return self.__is_closed
# Generate a GSMTC35 instance with a fake GSM "hardware" module
def generateGsm(in_waiting=50, read="OK\r\n", write=50, check_write="", is_open=True, is_closed=True):
level = logging.getLogger().getEffectiveLevel()
logger.setLevel(logging.CRITICAL)
gsm = GSMTC35.GSMTC35()
gsm.setup("COMundefined")
logger.setLevel(level)
gsm.serial = FakeSerial(in_waiting, read, write, check_write, is_open, is_closed)
return gsm
# All test
class TestGSMTC35(unittest.TestCase):
def test_FailToConnectToDevice(self):
level = logging.getLogger().getEffectiveLevel()
logger.setLevel(logging.CRITICAL)
gsm = GSMTC35.GSMTC35()
assert gsm.setup("COMundefined") == False
logger.setLevel(level)
def test_Reboot(self):
assert generateGsm(read="^SYSSTART\r\n",check_write="AT+CFUN=1,1\r\n").reboot() == True
# Launch all unit-test
unittest.main()
result:
> python test.py
..
----------------------------------------------------------------------
Ran 2 tests in 0.001s
OK
Since latest fix and improvements, python2.7 is not fully supported for sendSMS (mostly with special char).
It should be or at least it should not throw error if full python3/python2.7 is not possible.
The send/receive SMS fuctions are not supporting special characters very well (é, à, Chinese chars, ...).
To investigate.
Hi Quentin,
Super useful library! I'm loving it!
One issue that I did not manage to resolve - when I try to send
Python GSMTC35.py --serialPort COM3 --sendSpecialSMS +37125502235 "Hello Jānis"
I receive unreadable characters on my phone.
For tests, I'm using windows 10, Python 3.7
Is it possible to resolve this somehow?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.