Microbit MakeCode (PXT) extension intended to be used with Liki Cloud Connector hardware shield. Based on SIM7000. Enables GSM & GPS to reveal power of IoT.
Just add to your pxt.json
:
{
[...]
"dependencies": {
[...]
"cloudConnector": "github:LikiMobileSolutions/cloud-connector#master"
},
[...]
}
This block initialise Cloud Connector module
cloudConnector.init()
Returns signal quality in range of 1 to 5 or -1 in case signal quality can't be fetched for various reasons
cloudConnector.signalQuality()
Display signal quality on Microbit led matrix
cloudConnector.displaySignalQuality()
Returns gsm registration status code
cloudConnector.gsmRegistrationStatus()
return values:
0 - Not registered and not searching for available network
1 - Registered in home network
2 - Not registered but searching for available network
3 - GSM network registration denied
4 - Unknown Status
5 - Registered, roaming network
...Sends sms message using gsm network
cloudConnector.sendSmsMessage("+1222333444", "Hello")
Arguments:
1-st argument(telephone number): Receipment telephone number, must be in format +[2 digit country code][telephone number]
2-nd argument(content): Content of sms message, should not contain any special characters.
Handler for handling received sms message, content of this function will be executed when new SMS message will be received
cloudConnector.onSmsReceived(function (senderNumber, message) {
basic.showString("received SMS from: " + senderNumber)
basic.showString("message: " + message)
})
Arguments:
1-st argument(senderNumber): Telephone number of SMS sender, will be in format +[2 digit country code][telephone number]
2-nd argument(message): Content of received message
Return date and time from gsm network
cloudConnector.dateAndTime()
returns date and time string in format: yy/mm/dd,hh:mm:ss+tz.
Note: in case gsm network is not reachable it will return null
Initialize GPRS network and MQTT module
cloudConnector.initMqtt("Internet")
Arguments:
1-st argument(apnName): Operator APN name, this value depends on your sim card operator, just google it: "[operator
name here] apn name" and you'll get it.
Connect to MQTT broker
cloudConnector.connectToMqtt(
"broker_url.com",
"1883",
"microbit_sensor",
"johnDoe",
"superSecretPassword"
)
Arguments:
1-st argument(brokerUrl): Url address of MQTT broker server
2-nd argument(brokerPort): port number of broker server
3-rd argument(clientId): id of client, some descriptive string which will identify your client, can be chosen freely
4-th argument(username): Username for authentication by broker
5-th argument(password): password for authentication by broker
Publish message using MQTT protocol
cloudConnector.publishOnMqtt(
"myFancyTopic",
"message which will be published on 'myFancyTopic' topic"
)
Arguments:
1-st argument(topic): Topic on which MQTT message will be published
2-nd argument(message): message which will be published on topic provided in first argument
Subscribe on topic using MQTT protocol
cloudConnector.subscribeToMqtt("myFancyTopic")
Arguments:
1-st argument(topic): Topic on which you want to subscribe
Handler for subscribed topic, content of this block will be called when you will receive message on topic which you subscribed with MqttSubscribe block
cloudConnector.onMqttMessageReceived(function (topic, message) {
basic.showString("received message on topic" + topic)
basic.showString("message content:" + message)
})
Arguments:
1-st argument(topic): Topic on which message was received
2-nd argument(message): Content of received message
Initialize GPRS network and HTTP module
cloudConnector.initHttp("Internet")
Arguments:
1-st argument(ApnName): Operator APN name, this value depends on your sim card operator, just google it: "[operator name here] apn name" and you'll get it.
Do HTTP POST request
cloudConnector.httpPost("{'content':'can be json for example'}", "www.urlToPostTo.com")
Arguments:
1-st argument(data): data(body) of post request
2-nd argument(url): url to which you want make post request, reefer to HTTP protocol specification to learn more
Initialise Google Sheet writer
cloudConnector.initGoogleSheetWriter()
Initialise Google Sheet writer
cloudConnector.writeToGoogleSheet(["sth1", "sth2", "sth3"], "AKfaaabbbCCCdddeeeFFFggghhhIIIjjjkkkLLLmmmnnnOOOpppqMQ8")
Arguments:
1-st argument(data): Data to send to Google Sheets
2-nd argument(scriptId): id of script which will be used to save data in Google Sheets (Apps script)
Initialise/Enable GPS module, by default it's disabled.
cloudConnector.gpsInit()
Returns position string in format: lat,lon ex. "23.26577,-85.54324", you can use then this string to build google maps url to location for example:
https://www.google.com/maps/search/?api=1&query=23.26577,-85.54324
cloudConnector.getPosition()
Send plain AT command and returns modem response
cloudConnector.sendAtCommand("AT+CSQ")
Arguments:
1-st argument(atCommand): AT command to send
2-nd argument(timeout): Maximum time(in ms) to wait for modem response
Log debug message using serial USB
usbLogger.init(SerialPin.P0, SerialPin.P1, BaudRate.BaudRate115200, usbLogger.LoggingLevel.INFO)
Arguments:
1-st argument(txPin): Microbit pin to which TX pin of main part of your (hardware) solution is connected, ex
. SerialPin.P0
2-nd argument(rxPin): Microbit pin to which RX pin of main part of your (hardware) solution is connected, ex
. SerialPin.P1
3-rd argument(baudRate): Baud rate for communication with main part of your (hardware) solution, usually it will be
115200 baud, so ex. BaudRate.BaudRate115200
4-th argument(loggingLevel): TRACE / DEBUG / INFO / WARN / ERROR
Log message using serial USB
usbLogger.log("Something gone wrong", usbLogger.LoggingLevel.ERROR)
Arguments:
1-st argument(messsage): Message to log
2-nd argument(loggingLevel): message logging level
Log debug message using serial USB
usbLogger.trace("Some function called")
usbLogger.debug("Some event occured")
usbLogger.info("Importand event occured")
usbLogger.warn("Something gone not as expected, but can recover")
usbLogger.error("Something gone wrong")
Arguments:
1-st argument(messsage): Message to log
Some debug information can be fetched by connecting to Microbit serial port when logging level in init block was set to 1 or 2. For how to connect to Microbit serial port please refer to "using a computer terminal" paragraph under following link: https://support.microbit.org/support/solutions/articles/19000022103-outputing-serial-data-from-the-micro-bit-to-a -computer
This library consumes Microbit serial module, due to that during usage of this library you should not use "serial" module at all, as this will probably cause some problems. You can still log some message through USB serial but you should use dedicated block "usbLogger" provided by this library.
- for PXT/microbit
(The metadata above is needed for package search.)
Developed by Liki Mobile Solutions