Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 3:7b76a34e07c0, committed 2019-07-11
- Comitter:
- Sergey_K
- Date:
- Thu Jul 11 11:14:05 2019 +0000
- Parent:
- 2:16796fbfa94d
- Commit message:
- add new SD work
Changed in this revision
| Base64.lib | Show annotated file Show diff for this revision Revisions of this file |
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Base64.lib Thu Jul 11 11:14:05 2019 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/ansond/code/Base64/#4920bc5699f3
--- a/main.cpp Sat Jul 06 07:22:50 2019 +0000
+++ b/main.cpp Thu Jul 11 11:14:05 2019 +0000
@@ -6,6 +6,7 @@
#include <string>
#include "SDBlockDevice.h"
#include "FATFileSystem.h"
+#include "Base64.h"
#define GSMRX PA_9
#define GSMTX PA_10
@@ -40,16 +41,34 @@
uint8_t *receiveMsg[50];
char answer[300];
char sslBuffer[1402];
+ char * encoded;
+ string id_Stm;
//Прерывания
InterruptIn button(BUTTON1);
+InterruptIn sd_button(D5);
//Настройка пинов
DigitalOut myLed(LED1);
+DigitalOut RedLed(LED3);
+DigitalIn myButton(D5);
Serial sim800(GSMRX,GSMTX); //Serial communication of the sim800 and pc.
Serial pc(SERIAL_TX,SERIAL_RX);
//Инициализации SD карты
SDBlockDevice sd(D11, D12, D13, D4);
FATFileSystem fs("sd");
+Base64 n;
+void encodeBase64()
+{
+ pc.printf("Read uid !\r\n");
+ volatile uint32_t *UniqueID = (uint32_t *)0x1FFF7A10;
+ volatile uint32_t __UniqueID[2];
+ __UniqueID[0] = UniqueID[0];
+ __UniqueID[1] = UniqueID[1];
+ __UniqueID[2] = UniqueID[2];
+ size_t encodedLen;
+ char * encoded = n. Encode ((char*)UniqueID,12 ,&encodedLen);
+ pc.printf("STMuid:{%s} \ r \ n" ,encoded);
+}
//Настройка времени
void simTime()
{
@@ -75,8 +94,7 @@
wait(1);
}
//Отправка сообщения с дисплея
-void lcdStartWork() {
- myLed=!myLed;
+void lcdStartWork() {
message_t *message = mpool.alloc();
message->lcdData = request;
queue.put(message);
@@ -84,11 +102,25 @@
//Запись сертификата с SD карты
void sdReadSsl()
{
+
+ pc.printf("Read uid !\r\n");
+
+ RedLed = 0;
+ volatile uint32_t *UniqueID = (uint32_t *)0x1FFF7A10;
+ volatile uint32_t __UniqueID[2];
+ __UniqueID[0] = UniqueID[0];
+ __UniqueID[1] = UniqueID[1];
+ __UniqueID[2] = UniqueID[2];
+ size_t encodedLen;
+ char * encoded = n. Encode ((char*)UniqueID,12 ,&encodedLen);
+ pc.printf("STMuid:{%s} \ r \ n" ,encoded);
+ id_Stm = encoded;
sd.init();
fs.mount(&sd);
- FILE *fp = fopen("/sd/ssl.txt", "r");
+ FILE *fp = fopen((string("/sd/")+ encoded +string(".txt")).c_str(), "r");
if (fp == NULL) {
printf("Fail open txt file\r\n");
+ myLed = 1;
}
fread(sslBuffer, sizeof(sslBuffer), 1, fp );
fclose(fp);
@@ -109,22 +141,22 @@
message_t *message = (message_t*)evt.value.p;
*receiveMsg = (uint8_t*)message->lcdData;
printf("lcdData: %s\n\r" , *receiveMsg);
- if(timeCounter == 0)
+ if(timeCounter == 0)
{
timeCounter = 1;
- simTime();
+ // simTime();
}
sendAt("AT\r\n");
- /* sim800.printf("AT+FSDEL=C:\\USER\\SSL1.CRT\n\r");
+ sim800.printf("AT+FSDEL=C:\\USER\\SSL2.CRT\n\r");
wait(0.5);
- sim800.printf("AT+FSCREATE=C:\\USER\\SSL1.CRT\n\r");
+ sim800.printf("AT+FSCREATE=C:\\USER\\SSL2.CRT\n\r");
wait(1.5);
- sim800.printf("AT+FSWRITE=C:\\USER\\SSL1.CRT,0,1402,10\n\r");
+ sim800.printf("AT+FSWRITE=C:\\USER\\SSL2.CRT,0,1402,10\n\r");
wait(0.2);
sim800.printf("%s\n\r",sslBuffer);
- wait(1);*/
- sim800.printf("AT+SSLSETCERT=C:\\USER\\SSL1.CRT\n\r");
+ wait(1);
+ sim800.printf("AT+SSLSETCERT=C:\\USER\\SSL2.CRT\n\r");
wait(3);
answerCounter=1;
sendAt("AT+CCLK?\r\n");
@@ -138,6 +170,9 @@
sendAt("AT+HTTPINIT");
sendAt("AT+HTTPSSL=1");
sendAt("AT+HTTPPARA=URL,157.230.245.76:1880/message");
+ pc.printf("%s\r\n",id_Stm);
+ sim800.printf("AT+HTTPPARA=UA,%s-1.0.0\r\n",id_Stm);
+ wait(0.5);
sendAt("AT+HTTPPARA=CONTENT,application/octet-stream");
sendAt("AT+HTTPDATA=51,10000");
sim800.write(*receiveMsg,51,NULL,SERIAL_EVENT_TX_COMPLETE);
@@ -177,13 +212,23 @@
pressedButton=true;
//sdReadSsl();
}
-
+void sslButtonPressed()
+{
+ if(pressedButton==false) sdEvent.call(&sdReadSsl);
+ pressedButton==false;
+ //sdReadSsl();
+}
//Прерывание на отжим кнопки
void buttonReleased()
{
- myLed=!myLed;
+
pressedButton=false;
}
+void sslButtonReleased()
+{
+
+ pressedButton=true;
+}
//Задача для записи логов
void sdWork()
{
@@ -201,12 +246,15 @@
pc.printf("*******GPRS TEST*******\r\n");
- sdReadSsl();
+ myButton.mode(PullUp);
button.rise(&buttonReleased);
button.fall(&buttonPressed);
+ sd_button.rise(&sslButtonReleased);
+ sd_button.fall(&sslButtonPressed);
+
gsmTask.start(gsmStartWork);
- sdLogWrite.start(sdWork);
+ //sdLogWrite.start(sdWork);
eventThread.start(callback(&evq, &EventQueue::dispatch_forever));
sdEventThread.start(callback(&sdEvent,&EventQueue::dispatch_forever));