I use the same code in the iOS and macOSX two platforms to test, view the Runloop's activity switch, found that the results of the two platforms are not the same, what is the reason.s
Code:
1.create RunLoop Observer
CFRunLoopObserverContext context = {0,(__bridge void*)self, NULL, NULL, NULL};
_observer = CFRunLoopObserverCreate(kCFAllocatorDefault,
kCFRunLoopAllActivities,
YES,
0,
&runLoopObserverCallBack,
&context);
CFRunLoopAddObserver(CFRunLoopGetMain(), _observer, kCFRunLoopCommonModes);
2.print activity state
static void runLoopObserverCallBack(CFRunLoopObserverRef observer, CFRunLoopActivity activity, void *info){
Monitor *monitor = (__bridge Monitor*)info;
switch (activity) {
case kCFRunLoopEntry:
NSLog(#"activity_kCFRunLoopEntry");
break;
case kCFRunLoopBeforeTimers:
NSLog(#"activity_kCFRunLoopBeforeTimers");
break;
case kCFRunLoopBeforeSources:
NSLog(#"activity_kCFRunLoopBeforeSources");
break;
case kCFRunLoopBeforeWaiting:
NSLog(#"activity_kCFRunLoopBeforeWaiting");
break;
case kCFRunLoopAfterWaiting:
NSLog(#"activity_kCFRunLoopAfterWaiting");
break;
case kCFRunLoopExit:
NSLog(#"activity_kCFRunLoopExit");
break;
default:
break;
}}
The Result:
1.iOS
iOS Result
2.macOS
MacOS Result
Why are there multiple kCFRunLoopEntry in the macOS system?
Related
I am trying to get my ESP32 + RFM95C connected to The Things Network.
The Error I recieve is simple this:
24951: EV_JOINING
24970: EV_TXSTART
426696: EV_JOIN_TXCOMPLETE: no JoinAccept
And that repeats, Here is my setup code:
static const u1_t PROGMEM APPEUI[8]= { secret stuff here };
void os_getArtEui (u1_t* buf) { memcpy_P(buf, APPEUI, 8);}
// This should also be in little endian format, see above.
// static const u1_t PROGMEM DEVEUI[8]= { secret stuff here };
static const u1_t PROGMEM DEVEUI[8]= { secret stuff here };
void os_getDevEui (u1_t* buf) { memcpy_P(buf, DEVEUI, 8);}
// This key should be in big endian format (or, since it is not really a
// number but a block of memory, endianness does not really apply). In
// practice, a key taken from ttnctl can be copied as-is.
static const u1_t PROGMEM APPKEY[16] = { secret stuff here };
void os_getDevKey (u1_t* buf) { memcpy_P(buf, APPKEY, 16);}
static uint8_t mydata[] = "Hello, world!";
static osjob_t sendjob;
// Schedule TX every this many seconds (might become longer due to duty
// cycle limitations).
const unsigned TX_INTERVAL = 60;
// Pin mapping
const lmic_pinmap lmic_pins = {
.nss = 5,
.rxtx = LMIC_UNUSED_PIN,
.rst = 27,
.dio = {2, 26, 25},
};
void printHex2(unsigned v) {
v &= 0xff;
if (v < 16)
Serial.print('0');
Serial.print(v, HEX);
}
void onEvent (ev_t ev) {
Serial.print(os_getTime());
Serial.print(": ");
switch(ev) {
case EV_SCAN_TIMEOUT:
Serial.println(F("EV_SCAN_TIMEOUT"));
break;
case EV_BEACON_FOUND:
Serial.println(F("EV_BEACON_FOUND"));
break;
case EV_BEACON_MISSED:
Serial.println(F("EV_BEACON_MISSED"));
break;
case EV_BEACON_TRACKED:
Serial.println(F("EV_BEACON_TRACKED"));
break;
case EV_JOINING:
Serial.println(F("EV_JOINING"));
break;
case EV_JOINED:
Serial.println(F("EV_JOINED"));
{
u4_t netid = 0;
devaddr_t devaddr = 0;
u1_t nwkKey[16];
u1_t artKey[16];
LMIC_getSessionKeys(&netid, &devaddr, nwkKey, artKey);
Serial.print("netid: ");
Serial.println(netid, DEC);
Serial.print("devaddr: ");
Serial.println(devaddr, HEX);
Serial.print("AppSKey: ");
for (size_t i=0; i<sizeof(artKey); ++i) {
if (i != 0)
Serial.print("-");
printHex2(artKey[i]);
}
Serial.println("");
Serial.print("NwkSKey: ");
for (size_t i=0; i<sizeof(nwkKey); ++i) {
if (i != 0)
Serial.print("-");
printHex2(nwkKey[i]);
}
Serial.println();
}
// Disable link check validation (automatically enabled
// during join, but because slow data rates change max TX
// size, we don't use it in this example.
LMIC_setLinkCheckMode(0);
break;
/*
|| This event is defined but not used in the code. No
|| point in wasting codespace on it.
||
|| case EV_RFU1:
|| Serial.println(F("EV_RFU1"));
|| break;
*/
case EV_JOIN_FAILED:
Serial.println(F("EV_JOIN_FAILED"));
break;
case EV_REJOIN_FAILED:
Serial.println(F("EV_REJOIN_FAILED"));
break;
case EV_TXCOMPLETE:
Serial.println(F("EV_TXCOMPLETE (includes waiting for RX windows)"));
if (LMIC.txrxFlags & TXRX_ACK)
Serial.println(F("Received ack"));
if (LMIC.dataLen) {
Serial.print(F("Received "));
Serial.print(LMIC.dataLen);
Serial.println(F(" bytes of payload"));
//Now we sleep
esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
esp_deep_sleep_start();
}
// Schedule next transmission
os_setTimedCallback(&sendjob, os_getTime()+sec2osticks(TX_INTERVAL), do_send);
break;
case EV_LOST_TSYNC:
Serial.println(F("EV_LOST_TSYNC"));
break;
case EV_RESET:
Serial.println(F("EV_RESET"));
break;
case EV_RXCOMPLETE:
// data received in ping slot
Serial.println(F("EV_RXCOMPLETE"));
break;
case EV_LINK_DEAD:
Serial.println(F("EV_LINK_DEAD"));
break;
case EV_LINK_ALIVE:
Serial.println(F("EV_LINK_ALIVE"));
break;
/*
|| This event is defined but not used in the code. No
|| point in wasting codespace on it.
||
|| case EV_SCAN_FOUND:
|| Serial.println(F("EV_SCAN_FOUND"));
|| break;
*/
case EV_TXSTART:
Serial.println(F("EV_TXSTART"));
break;
case EV_TXCANCELED:
Serial.println(F("EV_TXCANCELED"));
break;
case EV_RXSTART:
/* do not print anything -- it wrecks timing */
break;
case EV_JOIN_TXCOMPLETE:
Serial.println(F("EV_JOIN_TXCOMPLETE: no JoinAccept"));
break;
default:
Serial.print(F("Unknown event: "));
Serial.println((unsigned) ev);
break;
}
}
void do_send(osjob_t* j){
// Check if there is not a current TX/RX job running
if (LMIC.opmode & OP_TXRXPEND) {
Serial.println(F("OP_TXRXPEND, not sending"));
} else {
// Prepare upstream data transmission at the next possible time.
LMIC_setTxData2(1, mydata, sizeof(mydata)-1, 0);
Serial.println(F("Packet queued"));
}
// Next TX is scheduled after TX_COMPLETE event.
}
Nothing all that special, just boilerplate sketch code.
I have a Dragino LPS8 LoRaWan Gateway with these settings:
Does anyone know why my connection will not go through?
It has been a while, and I have learned a LOT more about LoRaWan since I originally posted this question. I now know that OTAA will not work with a single channel gateway such as the dragino I had shown in the pictures. A gateway such as https://www.adafruit.com/product/4345 (an 8 channel gateway) would have been a better place for me to start this project.
I have an error when I compiling code: esp_sleep_enable_ext0_wakeup' was not declared in this scope
How can I fix this error? I use WEMOS D1. Please help
int bootCount = 0;
void setup(){
Serial.begin(115200);
delay(1000);
//Increment boot number and print it every reboot
++bootCount;
Serial.println("Boot number: " + String(bootCount));
//Print the wakeup reason for ESP32
print_wakeup_reason();
//Configure GPIO33 as ext0 wake up source for HIGH logic level
esp_sleep_enable_ext0_wakeup(D4,1);
//Go to sleep now
esp_deep_sleep_start();
}
void loop(){}
//Function that prints the reason by which ESP32 has been awaken from sleep
void print_wakeup_reason(){
esp_sleep_wakeup_cause_t wakeup_reason;
wakeup_reason = esp_sleep_get_wakeup_cause();
switch(wakeup_reason)
{
case 1 : Serial.println("Wakeup caused by external signal using RTC_IO"); break;
case 2 : Serial.println("Wakeup caused by external signal using RTC_CNTL"); break;
case 3 : Serial.println("Wakeup caused by timer"); break;
case 4 : Serial.println("Wakeup caused by touchpad"); break;
case 5 : Serial.println("Wakeup caused by ULP program"); break;
default : Serial.println("Wakeup was not caused by deep sleep"); break;
}
}
Even in included HTTP get demo sdk_wifi_station_get_connect_status() returns 255 even before try to connect. And of course it refuses to connect to
There is no any documentation this status.
Is there any suggestion on this issue?
you need to config the esp on user_init() function and call function sdk_wifi_station_get_connect_status() inside a task
#include "espressif/esp_common.h"
#include "esp/uart.h"
#include "FreeRTOS.h"
#include "task.h"
#include "ssid_config.h"
#include "esp8266.h"
void task1(void *pvParameters)
{
while (1)
{
check_wifi_connection();
}
}
void check_wifi_connection()
{
uint8_t status = sdk_wifi_station_get_connect_status();
while (status != STATION_GOT_IP)
{
status = sdk_wifi_station_get_connect_status();
vTaskDelay(ONE_SEC / portTICK_PERIOD_MS);
switch (status)
{
case STATION_WRONG_PASSWORD:
printf("WiFi: wrong password\n\r");
break;
case STATION_NO_AP_FOUND:
printf("WiFi: AP not found\n\r");
break;
case STATION_CONNECT_FAIL:
printf("WiFi: connection failed\r\n");
break;
case STATION_GOT_IP:
break;
default:
printf("%s: status = %d\n\r", __func__, status);
break;
}
}
}
void user_init(void)
{
uart_set_baud(0, BAUDRATE);
sdk_wifi_set_opmode(STATION_MODE);
sdk_wifi_station_set_auto_connect(true);
sdk_wifi_station_set_config(&config);// my config that
gpio_enable(gpio, GPIO_INPUT);
tsqueue = xQueueCreate(2, sizeof(uint32_t));
xTaskCreate(&task1,
"task1",
2048,
NULL,
tskIDLE_PRIORITY,
&task_handler);
}
Using Lumberjack in IOS7 on an ipod5, I Added a DDASLLogger to DDLog, and logged something. And used "asl_search" to get logs, but got nothing. When I did it on ios7 iphone simulator, I got what I exactly logged. Is it a bug of DDASLLogger?
I finally found the answer just now: YES. It's a bug recording to "asl_search only finds messages with ReadUID set". We need to set the ReadUID property for a message when sending it to ASL. Otherwise asl_search cannot find it.
The code of sending message in DDASLLogger is as following:
- (void)logMessage:(DDLogMessage *)logMessage
{
NSString *logMsg = logMessage->logMsg;
if (formatter)
{
logMsg = [formatter formatLogMessage:logMessage];
}
if (logMsg)
{
const char *msg = [logMsg UTF8String];
int aslLogLevel;
switch (logMessage->logFlag)
{
// Note: By default ASL will filter anything above level 5 (Notice).
// So our mappings shouldn't go above that level.
case LOG_FLAG_ERROR : aslLogLevel = ASL_LEVEL_ALERT; break;
case LOG_FLAG_WARN : aslLogLevel = ASL_LEVEL_CRIT; break;
case LOG_FLAG_INFO : aslLogLevel = ASL_LEVEL_ERR; break;
case LOG_FLAG_DEBUG : aslLogLevel = ASL_LEVEL_WARNING; break;
default : aslLogLevel = ASL_LEVEL_NOTICE; break;
}
asl_log(client, NULL, aslLogLevel, "%s", msg);
}
}
We just need to change
asl_log(client, NULL, aslLogLevel, "%s", msg);
to
aslmsg m = asl_new(ASL_TYPE_MSG);
asl_set(m, ASL_KEY_READ_UID, "501");
asl_log(client, m, aslLogLevel, "%s", msg);
It works. Thanks.
How to send the SMS using blackberry application?
you should check sms RIM API for that
http://myhowto.org/java/j2me/22-sending-and-receiving-gsm-sms-on-blackberry-using-rim-apis/
Detect the phone's network programmatically to send sms
public int getNetworkType() {
int type = 0;
int networkType = RadioInfo.getNetworkType();
switch (networkType) {
case RadioInfo.NETWORK_GPRS: // GSM
type = 0;
break;
case RadioInfo.NETWORK_CDMA: //CDMA
type = 1;
break;
case RadioInfo.NETWORK_IDEN: //GSM
type = 0;
break;
default:
type = 0; //GSM
break;
}
return type;
}